How can i create an array of objects of a certain class and also retrieve information from those objects?

I have something like this


I need to create an array of sockets, which are BP_Socket but are also in another blueprint, so they are Child Actors. After creating an array, I call a ‘for each’ loop and want to print volts for every socket. The type of array is Child Actor Component Object Reference, and because of that, the cast doesn’t work and gives an error:

and i can’t make the Sockets Array type of BP_Socket because each socket has the type of Child Actor. So how can I make it work?

I do not quite understand the problem occurring, but it would be best to use blueprint interfaces to obtain this data. To implement this, you would have a message node inside the for each loop. Said message node would get the relevant data from each socket. This would eliminate the need for casting and would not force the blueprint to be constantly loaded in memory.

Thanks for answer, i make it trough interfaces but now there is another problem (fixed).
First i need to say what this thing is. This is kind of a system. Here i have a Puzzle Blueprint, and in it some amount of Sockets Blueprint.

On BeginPlay every Socket in the world get unique amount of Volts.
Puzzle has Array Of Volts.
I have some amount of Puzzles in the world

What i need to do is set Puzzles Array of Volts according to it Sockets.
For example if i have 2 Puzzles it the world with 3 Sockets in each other, and
Volts of Socket1 of Puzzle1=1,
Volts of Socket2 of Puzzle1=2,
Volts of Socket3 of Puzzle1=3,
Volts of Socket1 of Puzzle2=4,
Volts of Socket2 of Puzzle2=5,
Volts of Socket3 of Puzzle2=6
Then Array Of Volts of Puzzle1 should be (1,2,3)
And Array Of Volts of Puzzle2 should be (4,5,6).

The problem is then i ran my game Puzzle2s array is equal to Puzzle1s array, which i fix right now by add a increment (all code below)

So i want to know if this code is ok? Or maybe there is a better solution? Or should i use OOP patterns? Or anything else?

Puzzle:

Here Make Array is for knowing amount of Sockets in Puzzle. And Node “Get Volts” Sends a message to Socket Blueprint. “Get Volts Event” is called from Socket BP.
Socket:

Node “Get Volts” Sends a message to Puzzle Blueprint. “Get Volts Event” is called from Puzzle BP.

If it works and doesn’t hurt performance, I’d say it’s fine.

1 Like