System for counting characters in my level

Jag vill ha ett enkelt system som räknar med hur många tecken som finns på min nivå för mitt temaparkspel. Jag vill ha några idéer hur det bästa sättet att göra detta.

Jag skapade ett nätverk som ska fungera som en grind. Jag antar att jag behöver en överlappande händelse där. Män hur vet systemet om det kommer att ta bort eller lägga till värdet. Är en port för att komma ut och komma in i parken.

Can a simple trigger box be the solution for this ? I mean drag it out over the level :). And then print it to a ui button on the screen ? :slight_smile:

Snälla hjälp:) :slight_smile:

What is creating the characters?
If I need something like this I will store a reference in an array.
So every time you add a new character add a reference to it to your character reference array. When ever you destroy a character, remove that one from array. Are you doing in C++ or BP?

In C++ might be something like:

TArray<ACharacter> CachedCharacters;

ACharacter * NewCharacter = <Create new character object>
CachedCharacters.Push(NewCharacter);

CachedCharacters.Remove(CharacterRef);

You can then use that TArray to count how many characters you have. Same principle if you are doing it in BP

Hello :slight_smile:

I am using both but the actor is a c++ class

it’s going to be a AI system for the characters later on. And also use character you can control you self to. :):slight_smile:

You could also have the characters add and remove themselves from an array or set stored on the gamemode. If you have a max number of characters that will be spawned at any given time and you have the memory for it, then preallocate the memory for the TArray to prevent a bunch of resizing and copying of the TArray.

Okay :slight_smile: . So what are the safest way to do this ?:smiley: So its not going to be bugs and problems later on .Let’s say you have like 30 different characters in the world . I’m not having yet but I will try to push this system . See how much it can store before going crazy :smiley:



for (TActorIterator<AActor> Actor(GetWorld()); Actor; ++Actor) {
    if ((*Actor)->IsA(AMyActorClass::StaticClass())) {
        // do something...
    }
}