Forum rules - please read before posting.

Object: Call Event - Having trouble changing a variable on my player prefab

edited July 6 in Technical Q&A


I have a few custom scripts on my player prefab. What I'm trying to do is use Action Lists to change the value of some booleans in those scripts.

Currently, I'm doing this via Object: Call Event, like so:

Let's take the Firing.EnableThrowing() as the example. With logging I can confirm the method EnableThrowing() gets called correctly.

Here's the method:

Yet if I poll the boolean in the update I see this:

I would expect everything after "throwing enabled" to say true. The problem I'm having is that any change to the variable doesn't seem to persist. There are no other calls or sets being done on the variable at this point so I'm really confused why this is happening.

To further add confusion, elsewhere I have methods in the same script like this which also change the boolean. When called, these seem to work fine and any changes persist correctly.

Are there any rules about about accessing scripts and changing variables on the player prefab at runtime that I'm unaware of? To ref the player I dragged in the prefab from the asset folders - is that a problem? Perhaps, is there fundamentally a different way I ought to be going about this?



  • edited July 6

    In the meantime I've had a go at creating a Custom Action to directly disable / enable the Firing component on the player.

    Already getting much better results. Also great to learn more about AC! Such a great bit of kit.

  • Be sure to send the message to the runtime instance of the Player, and not the original prefab. Your Player can be placed in the scene file in Edit mode to avoid having him be spawned in at runtime.

    Also note that the latest AC provides a new Variables component, which allows for AC variables to be attached to GameObjects, and can be manipulated with the standard Actions.

  • edited July 8

    @ChrisIceBox Like you say, I BET the prefab version was the problem. I'm going to leave this for now as the custom actions I wrote basically do a simple search through the scene hierarchy to grab the runtime instance of the player. It works (for now).

    That variable update sounds awesome. Will check it out.

  • See the front page of the Scripting Guide. The runtime instance of the player can be found with:

  • @ChrisIceBox

    Thanks. I keep forgetting all these useful variables AC offers!

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.
Do NOT follow this link or you will be banned from the site!