Forum rules - please read before posting.

Custom Action Not Retaining Values on Editor Options/Fields

I recently got into experimenting with implementing my own Custom Action classes. Most notably I created a Custom Action class that extends the functionality of the built in ActionSpeech class. I basically just extended the functionality of ActionSpeech to include 2 additional editor options: a simple boolean editor toggle field, and a Vector3 editor field. I then created a little dummy cutscene inside my test unity scene. In my dummy little cutscene I open up the ActionList editor and add one single action to the action list (i.e. one action that is my custom action). I then configure all the options of the custom action and then save the scene and quit completely out of unity. When I reopen unity and reopen my scene and look at the cutscene only the options that were already part of the base class of my custom action (i.e. ActionSpeech) retain their configured values; however, none of the new editor fields/options that I added as an extension of my custom class retained their value (i.e. the boolean editor toggle field and the Vector3 editor toggle field didn't retain their value)

I tried to look at the documentation but unfortunately it wasn't very helpful, only offering super vague examples relating to utilizing constant Ids, parameter ids, or something like that. This seems like something pretty basic that should just work as part of the contract of creating a custom action that extends the functionality of a base action.

Is there anyone that can provide a more concrete example to help resolve the issue I am experiencing?

Comments

  • edited December 2020

    Constant IDs and Parameter IDs are both AC concepts. Simply exposing a Vector3 or Toggle field doesn't involve AC - only Unity's API.

    Are your variables public or marked as [SerializeField]? Unity won't serialize (save) private variables otherwise.

    Without seeing the code itself, though, I can only guess generally. If you'd like specific help, share the code itself below and I'll take a look.

  • edited December 2020

    using UnityEngine;
    using System.Collections.Generic;
    if UNITY_EDITOR
    using UnityEditor;
    endif

    namespace AC
    {

    [System.Serializable]
    public class ActionDialogueExt : ActionSpeech
    {
    
        // Declare variables here
    
    
        protected GVar speechBubbleVariable;
        int chosenSpeechBubbleTypeIndex = 0;
        List<string> speechBubbleTypes = new List<string> 
        {
            "normal_point_left",
            "normal_point_middle",
            "normal_point_right",
            "shouting_point_left",
            "shouting_point_middle",
            "shouting_point_right",
            "thinking_point_left",
            "thinking_point_middle",
            "thinking_point_right"
        };
    
        bool applyPortraitSpriteRotation = false;
        Vector3 rotationVector;
    
    
        public ActionDialogueExt()
        {
            this.isDisplayed = true;
            category = ActionCategory.Dialogue;
            title = "Play speech ext";
            description = "Extension to Play speech with additional goodies";
        }
    
    
        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: 
             */
    
    
    
            return base.Run();
        }
    
    
        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.
             */
    
            base.Skip();
        }
    

    if UNITY_EDITOR

        public override void ShowGUI(List<ActionParameter> parameters)
        {
            // Action-specific Inspector GUI code here
    
            chosenSpeechBubbleTypeIndex = EditorGUILayout.Popup("Speech bubble type", chosenSpeechBubbleTypeIndex, speechBubbleTypes.ToArray());
    
    
            applyPortraitSpriteRotation = EditorGUILayout.Toggle("Apply Portrait Sprite Rotation?", applyPortraitSpriteRotation);
    
    
            if (applyPortraitSpriteRotation)
            {
                rotationVector = EditorGUILayout.Vector3Field("Portrait Sprite Rotation Amt:", rotationVector);
    
            }
    
            base.ShowGUI(parameters);
        }
    
        override public void AssignValues()
        {
    
    
    
            base.AssignValues();
        }
    
    
        public override string SetLabel ()
        {
            // (Optional) Return a string used to describe the specific action's job.
    
            return string.Empty;
        }
    
        endif
    
    }
    

    }

  • edited December 2020

    In C#, variables are private by default - they won't be serialized unless you tell them to be.

    Make chosenSpeechBubbleTypeIndex, applyPortraitSpriteRotation and rotationVector public for their values to be saved.

  • Yea that was the trick. Thanks so much for the assist on that; I forgot that little tidbit/gotcha about unity's serialization mechanism

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.