x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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.

Product Version: UE 4.10
Tags:
more ▼

asked Mar 17 '16 at 08:38 AM in Blueprint Scripting

avatar image

arronnax
39 10 10 11

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

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.

more ▼

answered Mar 17 '16 at 01:26 PM

avatar image

HungryDoodles
495 29 24 40

avatar image arronnax Mar 17 '16 at 03:29 PM

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.

playerdestroyed.png (305.7 kB)
avatar image HungryDoodles Mar 17 '16 at 04:01 PM

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.

avatar image Black Phoenyx Mar 17 '16 at 10:33 PM

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?

avatar image HungryDoodles Mar 18 '16 at 04:58 AM

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.

avatar image arronnax Mar 19 '16 at 09:10 AM

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.

avatar image HungryDoodles Mar 19 '16 at 11:47 AM

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.

avatar image arronnax Mar 20 '16 at 08:38 AM

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!

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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.

more ▼

answered Mar 17 '16 at 08:54 AM

avatar image

Black Phoenyx
4.2k 165 9 170

avatar image arronnax Mar 17 '16 at 03:08 PM

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.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question