Forum rules - please read before posting.

GameObject missing after save custom action

Hello,

I used ActionCheckTransform script present in this post https://adventurecreator.org/forum/discussion/9931/help-troubleshooting-a-custom-action-check-object-rotation-rounding-vector3 in my project.

Here is the ActionList:

And after saving:

The ActionList is saved in a folder into Assets.

I use:
Unity 2021.3.11f1
AdventureCreator v1.73.3

Thanks.

Comments

  • An asset file that references a GameObject in the scene will lose the reference when that scene is closed. A means must be then made for that connection to be restored again.

    AC provides a way to do this via the Constant ID system, whereby scene objects referenced by assets via a unique ID number. The Action needs to be updated to use it (see this tutorial), but once set up the re-connection process should be automatic.

    The Action's system code structure has also been streamlined since the other thread. Here's an updated version of gaius' original script, which fixes the issue:

    using UnityEngine;
    #if UNITY_EDITOR
    using UnityEditor;
    #endif
    
    namespace AC
    {
    
        [System.Serializable]
        public class ActionCheckTransform : ActionCheck
        {
    
            public GameObject objectToCheck;
            public int constantID;
            public Vector3 newVector;
    
            public override ActionCategory Category { get { return ActionCategory.Object; }}
            public override string Title { get { return "Check Object Transform"; }}
    
    
            public override void AssignValues ()
            {
                objectToCheck = AssignFile (constantID, objectToCheck);
            }
    
    
            public override bool CheckCondition ()
            {
                if (objectToCheck)
                {
                    // Check rotation of object
                    Vector3 objectRotation = objectToCheck.transform.eulerAngles;
                    //Convert Vector3 Euler angles to Quaternion
                    Quaternion a = Quaternion.Euler(newVector);
                    Quaternion b = Quaternion.Euler(objectRotation);
    
                    //Get angle between Quaternion values
                    float angle = Quaternion.Angle(a,b);
    
                    //Compare angle to some tolerance
                    return (angle < 1f);
                }
    
                return false;
            }
    
    #if UNITY_EDITOR
    
            public override void ShowGUI ()
            {
                objectToCheck = (GameObject) EditorGUILayout.ObjectField ("GameObject to check:", objectToCheck, typeof (GameObject), true);
                constantID = FieldToID (objectToCheck, constantID);
                objectToCheck = IDToField (objectToCheck, constantID, true);
    
                newVector = EditorGUILayout.Vector3Field ("Check has rotation value:", newVector);
    
            }
    
    #endif
    
        }
    
    }
    
  • Thanks Chris,
    The new script works perfectly even after reopening, and the explanations keep me going.

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.