npruehs / ue4-rts

Real-time strategy plugin and showcase for Unreal Engine 4.
MIT License
747 stars 151 forks source link

Fix missing sub-components when retrieved from default components #127

Closed jacopomaroli closed 2 years ago

jacopomaroli commented 4 years ago

From https://answers.unrealengine.com/questions/558236/how-to-get-a-component-from-a-classdefaultobject.html

When you GetDefaultObject(), you get only the root component and you're missing all the subcomponents.

In our case this causes an issue when placing a building: when attempting to set the acceptable destination range in the blackboard, you'll always get 0 as that's what you get when you attempt to GetShapeCollisionSize of the building UShapeComponent (that you'll fail to get)

This code will first attempt to work as usual, but if it fails, it will try to get the subcomponents from the blueprint definition.

P.S. Commit history is pretty pointless. Happy to squash and merge

jacopomaroli commented 3 years ago

After almost one year I find out you already had an implementation which does what I described so I just reused that. It works like a charm and it reaches the construction spot flawlessy.

In the demo you just have to tweak a bit the radius in the Behavior Tree (IIRC is fixed to 50)

npruehs commented 2 years ago

Thanks for the PR! :)