RealityStop / Bolt.Addons.Community

A community-driven project for extending Unity Bolt
MIT License
250 stars 34 forks source link

Get Nested Child Node #23

Closed RealityStop closed 2 years ago

RealityStop commented 3 years ago

A request popped up on the discord server:

image

RealityStop commented 3 years ago

My initial thoughts is this approach is fragile - a simple reorganization of your hierarchy shouldn't invalidate your code, and I'm not sure that promoting this approach is healthy for new users. However the node would be easy to write.

Thoughts?

BlindsidedGames commented 3 years ago

I don’t disagree with you but what about if you have a graph in a prefab and in that prefab you have a ton of child objects what would a better way than get child’s is there?

BlindsidedGames commented 3 years ago

image

BlindsidedGames commented 3 years ago

I mean it's relatively redundant now that I know about this, but could still be useful performance wise?

RealityStop commented 3 years ago

Setting event sources happens whenever the graph activates. In the case of a Flow Machine, that's on Awake, I believe. In the case of a state graph, it's whenever the state becomes active.

Another way you could handle this is use an object variable, with a GameObject/Transform/Whatever type. Because this is a child of the asset, even if you are using a macro, you'll be able to store references to the prefab's children. If you're using prefab variants, they'll all get the variable too, so you only have to set it once.

BlindsidedGames commented 3 years ago

Isn’t get child done whenever it’s called though? I feel like I would still prefer it even if just for the ability to change it during runtime

RealityStop commented 3 years ago

In that case I was referring to the example where the GetChild chain was feeding into an event target, which is only run once when the event listener is set up. If it's in the flow coming out of the event, then yes, it is run each time.

You can change variables at runtime too, and are probably the best fit for referring to deep child members at runtime. I know Bolt kind of hammers into your head that you can't store object references in Macros, but you can. You can't store SCENE object references, but references to other objects within the prefab will serialize just fine.

MasterSubby commented 2 years ago

I'm assuming this one won't be happening. Don't really have an opinion, but sounds like there isn't enough reasons or benefits. Feel free to comment or reopen if anything changes.