How to make an array of all Geometry Collection in a blueprint?

I want to add all geometry collections I have in a blueprint to an array, how do I do that? I want to know which array type is correct and how to add each Geometry collection to the array.
What I am trying to do is make an array that holds all the geometry collections from chaos fracture, and the array updates by removing which have been destroyed, until the player destroys everything causing the exit to open when the array is empty.

did you try get all actors of class then just save as array or add tag to them and use that. this is not cheap if you have lot of GC in level

Hey there @LonelyBox! There are lots of possibilities depending on if these geometry collections are ever different or procedurally generated in some way. Assuming they aren’t just staticly added before compile time, you could have them added to the array when created, though you can also find all of them under the actor by using Get Components by Class and just Set the array to it on creation or whenever you want to reboot them.

To remove the elements once they are broken you can use the On Chaos Break event (which you may need to bind to if you’re making these at runtime instead of hardcode as I demonstrate here), then pass a reference to a Remove Item node.

This example uses the event itself on an example component, but you could also just subscribe to the events for all of the components in the Get All GeoCol custom event if you were piecing these together at runtime. I use Component Primitive for the array here, which differs from your original a bit.

This doesn’t scale infinitely though, setting an array of many items is fine for sometimes but if you need to do this often you’ll need to be a bit more meticulous. It might even be more prudent to subscribe to those items with a manager in some instances, but chaos itself is also rather expensive so it’s best to keep the scope smaller in these instances.

I was planning to do that, but wanted to know if there were better methods to handle something like that. Thanks for the answer!

The geometry collections are small, but will be a good amount of them(maybe 100 to 200). Its going to just be one array for of these geometry collections for the game, so will it be too expensive? If it becomes expensive to do, is there something I could do to optimize?

Ahhh I misunderstood your intent. So you are trying to have an external class manage them not one inside it’s own class as components. This changes everything. You would have to use Get Actor of Class and actors is the primitive. Since it would be a manager type pattern, you would need to bind their break events or set up another custom method of listening for them.

100 to 200 simulating all at once? That might be rather heavy depending on how you’re intending to operate. You would also be updating the array frequently, which could be bad depending on a number of factors. I would recommend managing their pieces post break with Fields, as they are the best means of handling the individual pieces and their performance optimizations with sleeping and killing them when conditions are met.

What is your use case for the array? If I understand the bigger picture I could recommend a better design pattern.

The array manages all of the geometry collections in the level, when all of the geometry collections are destroyed it opens up the exit for the player (so when the array is empty). I have for each geometry collection the Scale on Removal and Remove on sleep options on. For the array would it be better for it to be in a blueprint with all of the geometry collections inside or will it be better for it to be separate and each geometry collection in a class of itself? I say 100 to 200 because they are small meshes, about 2x2 grid size.

If the geometry collections don’t need any extra (on board) management, leaving them as just their base actors with the chaos component should be fine. I believe you can subscribe to all of their On Chaos Break Event (assuming it’s in scope) when you load the level or spawn them. This would ensure you only need to do the quite expensive operation of getting them all once (unless you plan to spawn more).

High level pseudo code for that would be basically:

On Level Start → Get all actors of class → For each, Add to actor array, Cast to the component (might be unnecessary depending on scope but maybe not), Bind an event to On Chaos Break.

On Chaos Break → Remove item from array → Check if array empty

Not too different from my original method but also uncertain about the scopes. Edit: Also the array class could just be the actual class and you may not need to cast.

Thanks for everything!

No problem. Give it a try, and if there are issues with being able to subscribe to their events due to scopes, you could also do the component method. Good luck!