Casting from an Array

I am currently attempting to store a list of child actors in an array which I can reference to pull data from certain entries. The cast itself is casting to the “Master” entry (each object is a child of this master) but the cast fails each time. The array that stores the actors is an object reference array.

P.S.- I also added the master to my array and this cast failed as well.

Capture.JPG

1 Like

Are you doing this to avoid the ‘get child actor -> cast to child actor type -> access variable’?

No scratch that, I was assuming you mean child actor components.

It think you just mean level actors which are children of some parent, right?

If have a BP ‘MyFish’ and make a child ‘MyFishChild’, I can just put or spawn MyFishChild actors in the level and use them as such, no need to cast etc.

IF… you made other types of fish and wanted to have an array of them, then you would need to make the array of type Fish, and cast when you wanted to access stuff in the particular fish child type.

Does that make sense?

So you’re saying that you have a list of child actor COMPONENTS in an array, but the array is of type Object?
If so, you first need to cast the object to child actor component, then Get Child Actor, then cast that.

Changing array type would help more…

What I am hoping to do in this scenario is to generate a tile list of actors you can purchase and then place around the world. My current plan was to have an array that the Tiles referenced for each entry. When each entry is generated, it references the child actor that it represents to pull down price, name, and photo. I first attempted using an array type set to the Master BP (Decoration-Master) but this restricts me from adding anything to the list by default. ClockworkOcean, I appreciate your response but am having trouble wrapping my head around it. Is there a visual reference you could provide or point me to?

I would suggest changing the system to use an interface, just so that you do not need to cast.
Just loop through the item, use the Does Implement Interface to test, a branch to block the call if it does not, and call an interface function if true.

You need to hook up the models with the interface, and build their function, and you should be done.

From what you’ve described so far, I don’t think you need inheritence. You could just do this with a single blueprint.

Thank you for your help!