Reference parent object/component

krides

New member
Hi! I'm new to Behavior Designer, so I'm sorry if my question is a bit dumb or naive, but this is the first stumbling block I encountered.

I am writing a new task for my behavior tree, and I would like to use a generalized system (currently it's just a component on the gameobject the behavior tree is attached to) inside one or multiple tasks. Namely, I have an Environment Query System that I would like to use in my RunEnvironmentQuery task. What is the best way of doing it?

My immediate assumption would be that there's some way to get components on the entity the BT is attached to, but I can't find how to do it. gameObject seems to be null all the time.
 
Where are you getting the GameObject reference? Within a new task the gameObject variable is populated before OnAwake is called.
 
Hi! It looks like, I had two missing pieces:
1. I hadn't realized that I could create my own Shared types (which I now did for Environment Query). This way, I don't have to cast it from SharedObject and can reference it directly.
2. I was using an external behavior tree, and it seems like external behavior trees don't want to reference components directly (which makes sense scope-wise). The error just wasn't very clear, so it confused me.

It's all working now!

But I do wonder what is the best way of referencing stuff in the scene/on the entity the tree is attached to if it is an external behavior tree. Does it have to be a singleton always? Can I find the object the BT is attached to from its task? I'm still not sure how to best go about this.
 
Top