Announcement

Collapse
No announcement yet.

Hit performence with spawnactor

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Hit performence with spawnactor

    Hello,
    Im trzing to a TPS, something like serious sam games. I want to spawn multiple enemies when triggerplate is overlapped and i cant spawn moge then 4 actors at once(or actually one after the other in a loop). I tried to spawn them in a time period(i tried 0.001, 0.1,0.5 seconds per one actor) and I still cant get past 10 actors without engine crushing. How do I do that? In Serious Sam series there are dozens of enemies spawned at once.

    #2
    Strange that you cannot spawn more than 10 actors. Are they really heavy codewise or graphically? (and maybe your pc it's not powerful enough)
    Or maybe the engine is crashing for some other reasons, do you have any code in you actors that you are spawning? Try to debug more, because it's strange it shouldn't crash for 10 actors.
    But anyway I suggest you to check Object Pooling. You can use an ObjectPool to spawn actors more efficiently during runtime.

    A random video that I found:
    https://youtu.be/g4pAO01FFlQ
    Last edited by Matty37_; 03-27-2020, 10:10 AM.

    Comment


      #3
      Are the spawned actors ticking? If so, are they doing any hefty calculations on tick?

      Comment


        #4
        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:
        Code:
        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.

        Comment


          #5
          Logging is going to slow you down massively, comment out the UE_LOG. each log action takes around .10ms to 1ms depending on computer speed

          I'm not familiar with SpawnFromClass (is this your own function?), the standard way to spawn in a actor in c++ is to use SpawnActor()
          Last edited by ViperG; 03-30-2020, 05:14 PM.

          Comment

          Working...
          X