Forum rules - please read before posting.

Cursor not following script and changing in build

I seem to be having a lot of build issues, again. the script you helped me with that changes cursos depending on scene, doesn't have effect in build but does in Unity play. Is there something I am doing wrong on export build?

Comments

  • edited November 2021

    What's the exact code the script now uses, and how/where is it called from?

  • here is the script:

    /*
     *
     *  Adventure Creator
     *  by Chris Burton, 2013-2021
     *  
     *  "ActionTemplate.cs"
     * 
     *  This is a blank action template.
     * 
     */
    
    using UnityEngine;
    using System.Collections.Generic;
    #if UNITY_EDITOR
    using UnityEditor;
    #endif
    
    
    
    
    namespace AC
    {
        [System.Serializable]
        public class ChangeCursorsAction : Action
        {
    
            // Declare properties here
            public override ActionCategory Category { get { return ActionCategory.Custom; } }
            public override string Title { get { return "Switch Cursor Textures"; } }
            public override string Description { get { return "This switches the cursor textures"; } }
    
            // Declare variables here
            public Texture2D _newMainPointerTexture;
            public Texture2D _newWaitTexture;
            public Texture2D _newUseTexture;
            public Texture2D _newTalkTexture;
            public Texture2D _newLookTexture;
            public Texture2D _newPickUpTexture;
            public Texture2D _newExitRightTexture;
            public Texture2D _newExitUpTexture;
            public Texture2D _newExitLeftTexture;
            public Texture2D _newExitDownTexture;
    
            public override float Run()
            {
                /* 
                 * This function is called when the action is performed.
                 * 
                 * The float to return is the time that the game
                 * should wait before moving on to the next action.
                 * Return 0f to make the action instantenous.
                 * 
                 * For actions that take longer than one frame,
                 * you can return "defaultPauseTime" to make the game
                 * re-run this function a short time later. You can
                 * use the isRunning boolean to check if the action is
                 * being run for the first time, eg: 
                 */
                if (_newMainPointerTexture != null)
                {
                    AC.KickStarter.cursorManager.pointerIcon.texture = _newMainPointerTexture;
                }
    
                if (_newWaitTexture != null)
                {
                    AC.KickStarter.cursorManager.waitIcon.texture = _newWaitTexture;
                }
    
                if (_newUseTexture != null)
                {
                    AC.KickStarter.cursorManager.GetCursorIconFromID(0).texture = _newUseTexture;
                }
    
                if (_newTalkTexture != null)
                {
                    AC.KickStarter.cursorManager.GetCursorIconFromID(1).texture = _newTalkTexture;
                }
    
                if (_newLookTexture != null)
                {
                    AC.KickStarter.cursorManager.GetCursorIconFromID(2).texture = _newLookTexture;
                }
    
                if (_newPickUpTexture != null)
                {
                    AC.KickStarter.cursorManager.GetCursorIconFromID(3).texture = _newPickUpTexture;
                }
    
                if (_newExitRightTexture != null)
                {
                    AC.KickStarter.cursorManager.GetCursorIconFromID(4).texture = _newExitRightTexture;
                }
    
                if (_newExitUpTexture != null)
                {
                    AC.KickStarter.cursorManager.GetCursorIconFromID(5).texture = _newExitUpTexture;
                }
    
                if (_newExitLeftTexture != null)
                {
                    AC.KickStarter.cursorManager.GetCursorIconFromID(6).texture = _newExitLeftTexture;
                }
    
                if (_newExitDownTexture != null)
                {
                    AC.KickStarter.cursorManager.GetCursorIconFromID(7).texture = _newExitDownTexture;
                }
    
                if (!isRunning)
                {
                    isRunning = true;
                    return defaultPauseTime;
                }
                else
                {
                    isRunning = false;
                    return 0f;
                }
            }
    
    
            public override void Skip()
            {
                /*
                 * This function is called when the Action is skipped, as a
                 * result of the player invoking the "EndCutscene" input.
                 * 
                 * It should perform the instructions of the Action instantly -
                 * regardless of whether or not the Action itself has been run
                 * normally yet.  If this method is left blank, then skipping
                 * the Action will have no effect.  If this method is removed,
                 * or if the Run() method call is left below, then skipping the
                 * Action will cause it to run itself as normal.
                 */
    
                Run();
            }
    
    
    #if UNITY_EDITOR
    
            public override void ShowGUI()
            {
                // Action-specific Inspector GUI code here
                _newMainPointerTexture = (Texture2D)EditorGUILayout.ObjectField("Main Texture:", _newMainPointerTexture, typeof(Texture2D), true);
                _newWaitTexture = (Texture2D)EditorGUILayout.ObjectField("Wait Texture:", _newWaitTexture, typeof(Texture2D), true);
                _newUseTexture = (Texture2D)EditorGUILayout.ObjectField("Use Texture:", _newUseTexture, typeof(Texture2D), true);
                _newTalkTexture = (Texture2D)EditorGUILayout.ObjectField("Talk Texture:", _newTalkTexture, typeof(Texture2D), true);
                _newLookTexture = (Texture2D)EditorGUILayout.ObjectField("Look Texture:", _newLookTexture, typeof(Texture2D), true);
                _newPickUpTexture = (Texture2D)EditorGUILayout.ObjectField("PickUp Texture:", _newPickUpTexture, typeof(Texture2D), true);
                _newExitRightTexture = (Texture2D)EditorGUILayout.ObjectField("Exit Right Texture:", _newExitRightTexture, typeof(Texture2D), true);
                _newExitUpTexture = (Texture2D)EditorGUILayout.ObjectField("Exit Up Texture:", _newExitUpTexture, typeof(Texture2D), true);
                _newExitLeftTexture = (Texture2D)EditorGUILayout.ObjectField("Exit Left Texture:", _newExitLeftTexture, typeof(Texture2D), true);
                _newExitDownTexture = (Texture2D)EditorGUILayout.ObjectField("Exit Down Texture:", _newExitDownTexture, typeof(Texture2D), true);
    
    
            }
    
    
            public override string SetLabel()
            {
                // (Optional) Return a string used to describe the specific action's job.
    
                return string.Empty;
            }
    
    #endif
    
        }
    
    }
    

    It is called through an action list for RufusAppearance - Suited, tucked etc, which is called in scene OnStart, see screenshot:

    https://www.dropbox.com/sh/54z3jjyons1nsjt/AAA9eUikoKaLUfuJU8fDTLzxa?dl=0

  • I get no issue testing this in a build myself. Is it all cursor types that are unchanging?

    Check Unity's build log for relevant messages, but also be aware that this code makes changes to Unity's Cursor Manager, an asset file. You should run another such Action in your game's "ActionList on start game" asset to initialise your cursors to their default textures.

  • It is a handful of them and not all of them. I’ll try your suggestion and let you know
  • So basically set the script in start scene or start game asset?
  • It is a handful of them and not all of them.

    Which ones?

    So basically set the script in start scene or start game asset?

    Start game asset.

  • ok tried that and didn't work. It is main cursor and use cursor that are not being affected in build

  • Is there anything in the code or order of the code above that would not be letting the MAIN and USE cursor update on build?
  • edited November 2021

    Not that I'm aware of - as I said, it works on my end.

    You've confirmed that this does work for other interaction icons, e.g. Look? Compare the import settings for the textures involved, and check Unity's Player log for any relevant messages.

    Are any icons animated? What's your "Cursor rendering" field set to?

  • edited November 2021

    And it works for you in build changing between scenes? The icons are animated, and identical in frames and size. Settings for both sets fo cursors (use, use) are identical. Where is cursor rendering field again?

  • Where is cursor rendering field again?

    At the top of the Cursor Manager.

    If a cursor is animated, you need to use the ReplaceTexture function to update its texture. Instead of:

    AC.KickStarter.cursorManager.pointerIcon.texture = _newMainPointerTexture;
    

    Use:

    AC.KickStarter.cursorManager.pointerIcon.ReplaceTexture (_newMainPointerTexture);
    

    And it works for you in build changing between scenes?

    Without animated cursors, yes. With animated cursors, yes - once the above change has been made.

  • edited November 2021

    I get this error :
    Assets/Sleepytime Village/Scripts/CustomActions/ChangeCursorsAction.cs(91,17): error CS1656: Cannot assign to 'ReplaceTexture' because it is a 'method group'

    My cursor rendering is et to software

  • this is my script:

    /*
     *
     *  Adventure Creator
     *  by Chris Burton, 2013-2021
     *  
     *  "ActionTemplate.cs"
     * 
     *  This is a blank action template.
     * 
     */
    
    using UnityEngine;
    using System.Collections.Generic;
    #if UNITY_EDITOR
    using UnityEditor;
    #endif
    
    
    
    
    namespace AC
    {
        [System.Serializable]
        public class ChangeCursorsAction : Action
        {
    
            // Declare properties here
            public override ActionCategory Category { get { return ActionCategory.Custom; } }
            public override string Title { get { return "Switch Cursor Textures"; } }
            public override string Description { get { return "This switches the cursor textures"; } }
    
            // Declare variables here
            public Texture2D _newMainPointerTexture;
            public Texture2D _newWaitTexture;
            public Texture2D _newUseTexture;
            public Texture2D _newTalkTexture;
            public Texture2D _newLookTexture;
            public Texture2D _newPickUpTexture;
            public Texture2D _newExitRightTexture;
            public Texture2D _newExitUpTexture;
            public Texture2D _newExitLeftTexture;
            public Texture2D _newExitDownTexture;
    
            public override float Run()
            {
                /* 
                 * This function is called when the action is performed.
                 * 
                 * The float to return is the time that the game
                 * should wait before moving on to the next action.
                 * Return 0f to make the action instantenous.
                 * 
                 * For actions that take longer than one frame,
                 * you can return "defaultPauseTime" to make the game
                 * re-run this function a short time later. You can
                 * use the isRunning boolean to check if the action is
                 * being run for the first time, eg: 
                 */
                if (_newMainPointerTexture != null)
                {
                    AC.KickStarter.cursorManager.pointerIcon.ReplaceTexture = _newMainPointerTexture;
                }
    
                if (_newWaitTexture != null)
                {
                    AC.KickStarter.cursorManager.waitIcon.ReplaceTexture = _newWaitTexture;
                }
    
                if (_newUseTexture != null)
                {
                    AC.KickStarter.cursorManager.GetCursorIconFromID(0).ReplaceTexture = _newUseTexture;
                }
    
                if (_newTalkTexture != null)
                {
                    AC.KickStarter.cursorManager.GetCursorIconFromID(1).ReplaceTexture = _newTalkTexture;
                }
    
                if (_newLookTexture != null)
                {
                    AC.KickStarter.cursorManager.GetCursorIconFromID(2).ReplaceTexture = _newLookTexture;
                }
    
                if (_newPickUpTexture != null)
                {
                    AC.KickStarter.cursorManager.GetCursorIconFromID(3).ReplaceTexture = _newPickUpTexture;
                }
    
                if (_newExitRightTexture != null)
                {
                    AC.KickStarter.cursorManager.GetCursorIconFromID(4).ReplaceTexture = _newExitRightTexture;
                }
    
                if (_newExitUpTexture != null)
                {
                    AC.KickStarter.cursorManager.GetCursorIconFromID(5).ReplaceTexture = _newExitUpTexture;
                }
    
                if (_newExitLeftTexture != null)
                {
                    AC.KickStarter.cursorManager.GetCursorIconFromID(6).ReplaceTexture = _newExitLeftTexture;
                }
    
                if (_newExitDownTexture != null)
                {
                    AC.KickStarter.cursorManager.GetCursorIconFromID(7).ReplaceTexture = _newExitDownTexture;
                }
    
                if (!isRunning)
                {
                    isRunning = true;
                    return defaultPauseTime;
                }
                else
                {
                    isRunning = false;
                    return 0f;
                }
            }
    
    
            public override void Skip()
            {
                /*
                 * This function is called when the Action is skipped, as a
                 * result of the player invoking the "EndCutscene" input.
                 * 
                 * It should perform the instructions of the Action instantly -
                 * regardless of whether or not the Action itself has been run
                 * normally yet.  If this method is left blank, then skipping
                 * the Action will have no effect.  If this method is removed,
                 * or if the Run() method call is left below, then skipping the
                 * Action will cause it to run itself as normal.
                 */
    
                Run();
            }
    
    
    #if UNITY_EDITOR
    
            public override void ShowGUI()
            {
                // Action-specific Inspector GUI code here
                _newMainPointerTexture = (Texture2D)EditorGUILayout.ObjectField("Main Texture:", _newMainPointerTexture, typeof(Texture2D), true);
                _newWaitTexture = (Texture2D)EditorGUILayout.ObjectField("Wait Texture:", _newWaitTexture, typeof(Texture2D), true);
                _newUseTexture = (Texture2D)EditorGUILayout.ObjectField("Use Texture:", _newUseTexture, typeof(Texture2D), true);
                _newTalkTexture = (Texture2D)EditorGUILayout.ObjectField("Talk Texture:", _newTalkTexture, typeof(Texture2D), true);
                _newLookTexture = (Texture2D)EditorGUILayout.ObjectField("Look Texture:", _newLookTexture, typeof(Texture2D), true);
                _newPickUpTexture = (Texture2D)EditorGUILayout.ObjectField("PickUp Texture:", _newPickUpTexture, typeof(Texture2D), true);
                _newExitRightTexture = (Texture2D)EditorGUILayout.ObjectField("Exit Right Texture:", _newExitRightTexture, typeof(Texture2D), true);
                _newExitUpTexture = (Texture2D)EditorGUILayout.ObjectField("Exit Up Texture:", _newExitUpTexture, typeof(Texture2D), true);
                _newExitLeftTexture = (Texture2D)EditorGUILayout.ObjectField("Exit Left Texture:", _newExitLeftTexture, typeof(Texture2D), true);
                _newExitDownTexture = (Texture2D)EditorGUILayout.ObjectField("Exit Down Texture:", _newExitDownTexture, typeof(Texture2D), true);
    
    
            }
    
    
            public override string SetLabel()
            {
                // (Optional) Return a string used to describe the specific action's job.
    
                return string.Empty;
            }
    
    #endif
    
        }
    
    }
    
  • ReplaceTexture is a function - not a variable. See my example code change in my last post.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.