Hey all!
I’m making a respawn system. I have 1 problem that I cannot find a clean solution to.That is that when I spawn a new character and possess it, the beginplay has already run before possessing. That means that I cannot access the controller on beginplay since it’s not assigned yet. I’ve found a solution by using spawn actor deferred, then possessing and then finish spawning actor, however this will make it so the event possessed pawn changed on the controller returns a pawn with invalid components since they are not yet initialized.
Both problems can obviously be solved with delay untill next tick, but what is the best way to approach this issue?
Reuse the old dead pawn, don’t destroy it.
On death do a delay, then hide the mesh, set CMC movement mode to none, disable collision.
On respawn, reverse the process, teleport to respawn location, then possess.
Don’t forget to update your Health etc.
Thanks for the response!
Is this also used for more complex respawning situations? For instance I also have equipment, a lot of attributes and a lot more. It’s quite difficult to reset everything correctly
Typically yes. Create a function that sequences through all the reset steps.
End of day you have to weigh the performance costs of each method. If it’s cheaper to destroy the old and spawn a new pawn, then go that route. Generally its cheaper to reset.
There’s no guarantee when you’ll get the controller replicated or even when possession will occur time wise. All you can do is code around “eventually it will happen”. I’m currently using Polling for dependencies.
Overall it’s not good to have/rely on hard references. Interfaces would be better.