Forum rules - please read before posting.

Feature Request: Enable/Disable Game Object

Hi

Can you add an action to the list please? Under Object it would be great to have an Enable/Disable action that can take a parameter for the GO name.

Currently you can use the Call Event action which works but you can't pass it an Interaction parameter.

Thanks

Olly

Comments

  • Disabling a GameObject causes its references to become lost e.g. when loading a save-game file. It's too easy for newcomers to break things this way, so I'd prefer to keep it outside of AC's official Actions.

    A custom Action could do this, however:

    using UnityEngine;
    using System.Collections.Generic;
    #if UNITY_EDITOR
    using UnityEditor;
    #endif
    
    namespace AC
    {
    
        [System.Serializable]
        public class ActionTemplate : Action
        {
    
            public GameObject obToAffect;
            private GameObject runtimeObToAffect;
            public bool enable;
    
            public override ActionCategory Category { get { return ActionCategory.Object; }}
            public override string Title { get { return "Enable or disable"; }}
    
            public override float Run ()
            {
                if (runtimeObToAffect) runtimeObToAffect.SetActive (enable);
            }
    
            #if UNITY_EDITOR
    
            public override void ShowGUI ()
            {
                obToAffect = (GameObject) EditorGUILayout.ObjectField ("Object:", obToAffect, typeof (GameObject), true);
                enable = EditorGUILayout.Toggle ("Enable?", enable);
            }
    
            #endif
    
        }
    
    }
    

    A tutorial on incorporating parameters into custom Actions can be found here.

  • Would a more "AC Save Friendly" method be to just move the object in to the far distance of the scene somewhere ?

  • That would be the easiest approach, yes. If the performance of it being enabled but hidden isn't an issue, I'd recommend that as a general workflow.

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.