Casting to not working. Need to check parent of spawned child

So I’m working on an RTS where I have squads of soldiers as a unit rather than individual soldiers.
I’m now trying to do a selection function where if I click on one soldier in the squad, all soldiers in the squad should get selected.

The selection function is done in the “Base soldier” Character class. And I want to then check if the selected soldier is part of the squad by running a function in the “Squad base” Pawn class.

So I’m trying this to be able to send the “Base soldier” information over to the “Squad base”

While this seem to compile correctly it still fails and I can even get “Squad base” as a target variable.

Or is there a better way to send a check to see if a child of the parent(Base soldier) is present in an array in “Squad base”?

Use interfaces instead. So you avoid casting entirely.

1 Like