So actors im spawning are blueprint actors based on cpp class. The tick function in the cpp check if health==0 and destroys the actor if so. The tick function in blueprint checks whether actor is in ‘combat state’(close enought to hit me). Im new to this so i dont know if this is the right way to code such things. The actors work perfectly when they are already placed in level when the game starts(even if there is hundred of them). I will look into the matter of object pooling, but maybe there is something else.
The code that spawns the actors looks like this and its in a separate trigger actor that i place in my level and it activates on overlap:
Super::Tick(DeltaTime);
UE_LOG(LogTemp,Warning,TEXT("%f"),FPlatformTime::Seconds()-Time)
if(TimeStart)
{
Time = FPlatformTime::Seconds();
TimeStart = false;
}
if(IsOverlapped && (FPlatformTime::Seconds()-Time>0.5))
{
UE_LOG(LogTemp,Warning,TEXT("in"))
switch(Stage)
{
case 1:
SpawnFromClass(Minotaur,Location[Counter%4]);
if(Counter<=0)
{
Destroy();
}
Counter = Counter-1;
TimeStart = true;
break;
}
}
So every 0.5 second it spawns one actor at a location that is stored in Location array. SpawnFromClass function spawns the actors and their AI controllers Counter controls how many actors are left to spawn. The Switch case part is there because in future I wanted to have this actor spawning different amounts of enemies in different stages of the game.
I know this codes look awful but i wanted it to work and then maybe refactor it, im still learning the basics of programming in ue4.