Under review

OnVariableChange doesn't work when an outside object changes the variable?

TrumTrum 9 months ago in Game Creator updated by Marti (Lead Developer) 9 months ago 5

I am trying to change an Invoker's Gameobject variable with a gameobject seperate from its invoker, which works, however my OnVariableChange Trigger for the variable (The Trigger is a component of a child object of the Invoker object) doesn't get called when I can clearly see it changing in the inspector. The variable type is GameObject.

Unity version:
Unity 2018.4.15f1 (LTS)
Game Creator version:
Under review

Can you provide some screenshots of the setup? Make sure each screenshot shows the name of the object so we can understand what's going on. Otherwise it's a bit difficult for us to imagine what's going on.

  • CallsChangeVariable - Holds a Trigger component with OnMouseDown(left) that calls ChangeVariable actions
  • LocalVariables - Holds the Local Variables component with a GameObject variable called Variable (the one to be changed). It is null until called to change.
  • OnVariableChange - Holds a Trigger with OnVariableChange when Variable changes and calls LogThatVariableHasChanged action (this doesn't get called)
  • ChangeVariable - A child of another GameObject (empty) that holds an action to change the invoker's Variable to ChangeToThis. (this works)
  • In runtime after leftclick, no message

OnVariableChange is not being called as I'm not getting the debug message

I have tried not accessing Variable through invoker and instead dragging 'LocalVariables' onto it and choosing Variable which actually works fine (I get the debug message) except, in my project, I don't want the constant Variable from the same object every time its called.

My title doesn't ask the right question, it should be "OnVariableChange doesn't work when the variable is referenced/changed using invoker path?"

what are you exactly wanting to do?

For example changing variables on collision from an invoker and setting something else afterwards.

I find it difficult to understand what you are wishing to do.

write it down, I want to do this, then this happens and when that happens do this or that..

build up your logic first. 

Then people can tell you exactly how to do that what you are wanting to do.

I want OnVariableChange to work... Maybe should have categorized it as a bug. I'm not asking how to do something, I'm asking "is this not suppose to work?".

I said what I was trying to do in the original post.

Hi Trum Trum;

I believe the problem is that the Invoker is not always the same. You see, when you call the "On Mouse Left" Trigger, the Invoker is the Player. However, when you execute the "Change Variable" Action directly using the little Play button, the Invoker is set as the game object itself.

I'm hoping to work on a tool to make it more clear what each Action and Condition refers to when using the Invoker property.

But as a general rule of thumb, the Invoker references the object that is responsible for executing the chain of Actions or Conditions. For example, if an object collides with another one, the collided object will be the Invoker, and so on.

If you are not sure what the Invoker refers to, you can use the "Debug Name" Action and print the name of the Invoker.