Transform variable of behavior object

Pedro

Member
I created a variable that is the transform.position of the object. However, I didn't see how I could select a generic transform.position of the object this behavior tree is running on. I could select the exact object in the list with the > button but that isn't very flexible because if I clone the object or make a prefab with the behavior tree and launch multiple objects with the behavior tree attached it won't be filling that variable with the position of the object the behavior tree is running on.

I'm not sure if I've explained my question clearly, but basically I just need a variable that would give me the transform.position of the object the behavior tree is attached to at any given time.

Thanks
 
You can use the SharedVariable system in order to access that transform (and position) from a task:


Or from a regular script:

 
From what I understood in the first document on shared variables I still have to select the variable from a "hardcoded" object reference:

VariableMapping.png


My understanding on how it works based on the image above taken from the first document (and my experiments), it would get the variable from the object "Agent". If Agent was respawned it would still be referencing the original hardcoded "Agent" object.

I must be missing something. Any screenshot of how to get the variable from the active gameobject the behavior tree is attached to?

Or does the SharedVariable require I create and attach a script with the shared variable defined as in the example here: https://opsive.com/support/documentation/behavior-designer/writing-a-new-conditional-task/? That would seem a bit overkill to just access the transform of a gameobject but if that's the only way I can do that too.
 
I guess that I'm not completely following what you are trying to do. That image is using property mappings which has to be mapped to a property on a GameObject. If you want to get the position of the current GameObject you can use the GetPosition task.
 
Top