Get variable from other Game Object to compare

DeanMarquette

New member
I don't see a simple way to get a variable from another game object. Lets say Object 1 has Health int = 10 and if it sees Object 2 and Object 2 also has Health int = 10 then do something.

I can store Object 2 if I see it so how come I cant get its Health int ?
 
The easiest way would be to create a small task which does that, or you could use the reflection tasks. Reflection is slow though so I recommend creating your own task for that.
 
Okay I give up, I'm not fluent enough of a coder to pass the int from Object 2 to Object 1 via a task.
To get a value in another script and check it use the conditional>reflection>get field value (not the property value).
Now your scripts values should be accessible by behaviour designer.
In my example the Compare Field Value is on my enemy AI and the script has been selected and I've chosen to check the status of whether the enemy is alive or not. If the enemy is alive it will be successful in playing the tree if false it will skip whatever is in that sequence.

1621750361433.png
In the second example the bool is checked to false meaning that if the enemy is dead the other tasks will not run which is correct if the enemy is not alive he should stop the other tasks. The two sequences have "lower priority" and are updated every framer thanks to the repeater which is set to repeat forever. So there in the Compare Field Value Sequence of the image below you can add more tasks to then play your death animation and wait 2 sec then fade the enemy out.
1621751032913.png
 
Last edited:
Top