Forum rules - please read before posting.

Custom ActionList and Custom Action

After building game, when try to call custom action from action list that is in asset folder (trigger from interaction in the scene) it's not working. In editor all work good.
When I'm calling custom action from interaction (or trigger) in the scene, all work good to.

Comments

  • Welcome to the community, @BostonLeeK.

    There should be no difference in ActionList behaviour between Builds vs Editor. The issue may be related to the Action itself.

    Can you share the exact code you're using, and are your Error Logs revealing anything?

  • edited August 2020

    There is no error's in log file;
    Code:

    [System.Serializable]
    public class ActionChangeSortOrder : Action
    {
    
        public GameObject objectToAffect;
        public string layerName;
        public int sortingOrder;
        public int parameterID = -1;
        private int constantID;
    
    
        public bool affectOnChildren;
    
    
        public ActionChangeSortOrder()
        {
            this.isDisplayed = true;
            category = ActionCategory.Custom;
            title = "Change Sort Order";
            description = "Action to change sort order of the sprite.";
        }
    
    
        public override float Run()
        {
    
            if (objectToAffect)
            {
    
                if (!affectOnChildren && objectToAffect.GetComponent<SpriteRenderer>())
                {
                    objectToAffect.GetComponent<SpriteRenderer>().sortingLayerName = layerName;
                    objectToAffect.GetComponent<SpriteRenderer>().sortingOrder = sortingOrder;
                }
                else if (affectOnChildren)
                {
    
                    foreach (Transform child in objectToAffect.transform)
                    {
                        child.GetComponent<SpriteRenderer>().sortingLayerName = layerName;
                        child.GetComponent<SpriteRenderer>().sortingOrder = sortingOrder;
                    }
                }
            }
            return 0f;
        }
    
    
        public override void Skip()
        {
            Run();
        }
    
    
    #if UNITY_EDITOR
    
        public override void ShowGUI(List<ActionParameter> parameters)
        {
    
            parameterID = Action.ChooseParameterGUI("GameObject to affect:", parameters, parameterID, ParameterType.GameObject);
            if (parameterID >= 0)
            {
                constantID = 0;
                objectToAffect = null;
            }
            else
            {
                objectToAffect = (GameObject)EditorGUILayout.ObjectField
                   ("GameObject to affect:", objectToAffect, typeof(GameObject), true);
    
                constantID = FieldToID(objectToAffect, constantID);
                objectToAffect = IDToField(objectToAffect, constantID, true);
            }
    
            layerName = EditorGUILayout.TextField("Sorting layer:", layerName);
            sortingOrder = EditorGUILayout.IntField("Order in Layer:", sortingOrder);
            affectOnChildren = EditorGUILayout.Toggle("Affect on children:", affectOnChildren);
            AfterRunningOption();
        }
    
        override public void AssignValues(List<ActionParameter> parameters)
        {
            objectToAffect = AssignFile(parameters, parameterID, constantID, objectToAffect);
        }
    
        public override string SetLabel()
        {
    
            if (objectToAffect)
            {
                return (" (" + objectToAffect.name + " - " + layerName.ToString() + " - " + sortingOrder.ToString()  + ")");
            }
            return "";
        }
    
    #endif
    
    }
    

  • Your "constantID" is private. Make it public, or mark is as [SerializeField], so that its value is saved when set in ShowGUI.

    For asset-based Actions to affect objects in the scene, they use the Constant ID value to locate them at runtime. You'll need to reopen the Action in the Editor once done to save the changes once more.

  • Fix but this not help. If it was error why everything okay in play editor? And not work only after build.

  • edited August 2020

    My hunch is that private data is stored temporarily and may still be set when running in the Editor. Whether or not this is the only cause of the issue, it was important to address.

    Did you re-assign the "GameObject to affect" in the Action to set a new Constant ID value?

    As the above fix was related to asset files, what is the effect of using the Action in the scene only? Try creating a Cutscene in your scene that affects an object in that same scene - so that no assets are involved. Does that work in the build?

    Assuming so, place the following Log statement into the top of your Run() function.

    Debug.Log ("Running custom Action. Object: " + objectToAffect + ", ConstantID: " + constantID);
    

    That should then reveal the field values in your Unity Logs. What do they show when running from an asset file?

  • I'm not assigning GameObject by myself. I'm throwing it dynamically. Add screenshots: https://drive.google.com/drive/folders/1eWdJHHx_4AW1P3MjUqIOUnSidjY7J-c7?usp=sharing

    Will more check with Debug.

  • Move the AssignValues function out of the "UNITY_EDITOR" block - it's necessary when using parameters to override field values, and won't be part of the build otherwise.

  • Yes, it was a main problem) My mistake. Thank u for help!

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.