Adding a delay before respawn

The game freezes at the point of delay when the player tries to respawn. I’ve tried creating my own custom timer, loops or using Set Timer by Function name but they dont seem to work either.

Someone asked a similar question before but never got a working solution.

It most likely can’t run the function because the actor is pending kill…try instead of constantly destroying actors and spawning new ones quickly reset the player variables to their starting points and teleport the play back to their starting point…you can even setup a fade in and fade out effect with a matinee if you wanted to add something else to it.

Wowow, no-no-no, character should not handle any respawn routines, left it to GameMode instead. Call player’s pawn dead event or something like that in GameMode class and let GameMode spawn new character and make controller possess it. That very simple!
I don’t see any problems with blueprints, but I sure that if you get rid of respawn inside of charated and move it to GameMode the problem will get away.

Oh ok. Yes I was told “teleporting” the player instead of destroying the actor was a good way to do it; saves on memory and is a good coding practice. Will try to incorporate that.

Yes I did try to do that. I’ve tried bringing the respawn function over and there’s no event destroyed event for my character.

However, I am having problems retrieving the player character’s variable, namely SpawnTransform (player’s spawn coordinates when the player touches a checkpoint) I tried using Get Player Character, Pawn, Controller and seems like only Controller can compile but doesn’t execute the intended result.

This is my current blueprint in my game mode.

From controller → Get Controlled Pawn. Checking it for validity will be great indicator to check if respawn needed. There is must be little delay anyway, at least 1 frame. Actually Player Controller should send event to GameMode about it needs respawn it’s character because he is dead. Event or delegate named “Unpossess(ed)” is being called when PlayerController loses it’s Pawn if I am not mistaken.
You trying to check if Player Controller actor does exist in scene, this will always return true.

Constantly spawning and destroying actors has a cost on performance, resetting variables and moving an actor to a location is much less costly than spawning a new one and unpossessing and repossessing, if he doesn’t want to handle the reset in the character it could be moved to the controller or game mode. Think of it like this…which is cheaper on performance spawning 50 actors at once or setting variables in 50 preexisting actors at once?

Pfff…
Computers today are beasts, spawn of one nice character will take you 1 ms in worst scenario (on very-very bad machine). For example in my FPS game I can spawn 32 characters in one frame (this situation will never exist in real case scenario) and on my mid-spec PC it takes 4-5 ms, what isn’t actually noticeable.
But this will be necessary for bullets. E.g. when I want to spawn 500 bullets in one frame it will take 150-200 ms if they are actors, what is unacceptable, so in my case I have used prespawned bullets, but they isn’t actors, they are simple classes. Now it takes 25-30 ms including the fact that Launch function is dem big and contains much of debug info.

Ok I did try Hungrydoodles’ suggestion of putting the respawn in the game mode and the character respawns perfectly with a delay but I’m trying hard to understand why a delay wouldn’t work if placed after Event Destroyed or OnDestroyed INSIDE the character blueprint. I’m not a programmer by trade but am trying to practice object-oriented programming.

Part of the reason why I’m not creating a custom Destroy function (teleports player to spawn point upon death) is because I’m trying to learn how to simply respawn the player by recreating and repossessing with a delay upon destroyed inside the character blueprint. If that can’t be done, that’s fine. I just want to know if it is possible before exploring alternative means to respawning the player.

Aside from respawning, I’ve tested with other things on Event Destroyed and it executes perfectly (Eg. spawn projectiles or emitters and so on) but for some reason, adding a delay just causes that to freeze up.

Ah, now I understood, haven’t noticed event destroyed before.
Character needs to be respawned only when his health is less or equal to zero. If you will try to respawn without Delay then respawn procedure will execute immediately and character will be destroyed after respawn, so you got new character.
If you will try to respawn with Delay then respawn event will be executed, but as soon as process will reach Delay, it will force character to skip at least one frame before execute next nodes. But there is a problem - character is pending to be destroyed and it will not exist in the next frame, so there is nothing to execute after delay. I mean if we will follow workflow:
->Event OnDestroyed called.
->Execution reached Delay node, execution of next nodes postponed.
->Event OnDestroyed has finished execution.
->Stop all actor routines and destroy actor. End of actor life cycle.
So nodes after will not be executed - there is already no character.

I see I see…no wonder the segment on respawning players in the UE4 doc put the respawn in GameMode rather than character.

Thanks for the in-depth explanation!