Download

Group actors into groups and remove them en masse

Hi, I have procedurally generated world and I need to delete actors when they are too far away from player. My world is divided into invisible grid and I want to remove all the actors in that grid at once. How can I group them and remove them all at once?

This isn’t really my field of expertise, but I know that you can combine different levels using World Composition. You can also load/unload different parts of the composition, so I think this is what you are looking for.

I guess you mean Level Streaming, which I cannot use because I procedurally build my world at runtime, so I cannot use those functions.

Also, I already have mathematical mechanics for loading/unloading, all I need is a way to utilize them.

AFAIK, you have to remove each one individually. I have a spawn manager that checks for any players in the area, if none, goes through that list and remove them.

Yeah I expected they are removed one by one from some kind of list, but I need more than that, I need specific way I can store large amount of actors, classify them and destroy them. Some code or link for further searching, stuff like that.

Umm I still need the answers, please, somone…

Nothing?! I need the answers, at least some…

Store large amount of actors

Load actors into following arrays:




TArray<AActor*> ActorGroup1
TArray<AActor*> ActorGroup2
etc

for (AActor* a : ActorGroup1)
{
a.destroy()
}


Repeat.

Oh so I can use containers for storing pointers to all the actors I need?! Can I use TMultiMap for storing them in specific groups and then removing one key-group when needed?

I do not mean to offend, but this is a basic concept in programming with C++.

I have not used TMultMap. Beware that some of these containers may not be supported in Blueprints.

I’d like to mention that mass deleting actors will cause an fps stutter (probably a big one) if you are doing it from the main thread.

No offense taken, I am new at C++ and I dont intend to use Blueprints.

And is there a way to do it without significant performance drop? Or do I have to learn multi-threading? I am definitelly going to do multi-threading, but it seems like high-level stuff to learn so I have not yet touched that concept.

You’re better of just setting up proper culling. Another option would be to use prefabs. This will make your destroy list a lot smaller. The list itself would be TArray (Actor Object Reference).

I aim to have procedurally generated world that generates and destroys around player as they move, I doubt culling will be enough, as I would be left with thousands upon thousands of objects. Also what is the difference between C++ Actor class and prefab?

A prefab is a class containing multiple actors/components as a single prop. An example would be a building or a group of buildings, its interior décor/props, lighting, reflection spheres etc.