Forum rules - please read before posting.

Turn on and off the player's component

Hi Chris,

I am really confused about this problem, hope you can help, thanks.
Initially, I have only one Player. And I use call event action list to enable/disable one of the component attached to the Player.
It has no problems.
However, when I add one more Player and set the Player can be switchable. Problem arises.
The call event seems fail to work again to enable or disable the Player component.

I check the actionlist in runtime. I found that the Call event actionlist can't find the component anymore.
The object column becomes missing.
So I change back to non switchable Player setting, the call event work again.

I am really confused about it. Would you please help?
I use the AC version 1.70.4
Unity version 2019.3.0a7

Comments

  • When using Player-switching, all Players are spawned in at runtime - so an Object: Call event Action will not be able to reference this object directly, since the object that you want affected doesn't exist at the time you create the Action.

    You can instead use the Object: Send message Action to trigger a function by name. The advantage of this Action is that, when referencing a prefab, will note that prefab's Constant ID value (if one exists), and use that ID to find its scene instance at runtime.

    If you want to disable a particular component, create a new C# script that contains a public function to handle this, i.e.:

    public void DisableMyComponent ()
    {
        GetComponent <MyComponent>().enabled = false;
    }
    

    (Where "MyComponent" is the name of the component you want to disable)

    You can then use the send message Action, send a Custom message named "DisableMyComponent", which will run the function.

    Another way to disable a component at runtime is to use Animation, which you can trigger with AC's Object: Animate Action.

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.