clone charactor

hey guys, just started with unreal a week or two ago, past coding as well. learning curve however. anywho, i am trying to clone my charactor based on the troop count i will implement later. currently this is my clone code which works however i am going to need about 10-20 clones and if i spawn that many it is a large code and it spawns that many actor actor classes which is performance heavy. heres the clone.


now i feel like there has to be a simpler less performance heavy way to clone that many. all characters would be a few vectors over without much or any overlap.

secondly following this i need all the clones to move directly and the exact same as the main controller(the player). the troops are grouped and follow a mouse follow code i have. now for the life of me i cannot get my clone in this way to follow my movements. not follow but copy my movements. ive tried with the keyboard inputs and mouse and they never move.

heres the clone code movement i use which is an event dispatcher to clone bp.


this picture is mouse movement follow with event dispatcher , second is clone copy

my overall question is , can i avoid spawning all those actors that are heavy and just duplicate it within my charactor blueprint as well as i need to figure out exact coords around original guy to spawn them so if theres an easier way to spawn multiples around me. however if i can do it all in my 1 charactor bp it would make it easier to get them all to copy my movements if any code is required at all.

thanks. trying to do something like this from this game.
gg

a few things:

  • do these need to be of type ACharacter? APawn is a lot simpler in terms of overhead, and you might be able to getaway with AActor though this can implications with regards to how animations work.
  • does each of these “need” to be a separate Pawn or Actor, where there is a practical platform limit on the number of active actors in the level at a time before you start having performance issues.

a major consideration/suggestion is to not have these be Characters. maybe thinking of the Character as the Camera, or the zone the Actors occupy, will help this.

some considerations what you could do is create a struct which is a Transforms (could be a Vector3 as it will be an offset), and a bool (maybe a state enum but start small), you could even have an object pointer to one of these actors for validation. When you go to spawn one of these Actors/Pawns sweep through an array of these structs till you find one that has the state bool as false; spawn the actor at that offset (NewActor->Transform.SetLocation(ParentTransform.GetLocation() + OffsetTransform.GetLocation())), set the state bool to true, and then Attach the spawned actor to the “character”
To save the seek time you could maintain 2 separate arrays of these structs one for “active” and the other for “not Active” that way it is faster to sweep through.

if you are experiencing hitches and stutters around the moment of spawning the is probably because the platform you are running on, and that SpawnActor has a bit of weight especially if the class is not fully loaded, or has complex startup code.
if you want to have the number of actors grow and shrink semi-rapidly you might want to look into “object pooling”, and maybe having a minimum reserve of actors just in case, because suddenly spawning 5 actors will incur a hit to performance, and the performance hit will stack up. if you are trying to spawn more then 5 actors at an instant you should have probably pre-spawned most of them. (you should “know” in some way what the number being added will be whether these are custom built or randomly generated gates)

It’s not necessarily that performance heavy to have many instances of a given Pawn or actor class, in a situation like this, id work on controlling them with an AI controller though, trying to control them all with player controller would be very heavy