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"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

How To Access (Actor)Variable After Actor Is Destroyed?

Curious on how to manage Variables on NPCs (health, is the NPC dead)...

Below is the scenario:

  • There is a HERO (the player) - MyCharacter Blueprint

  • Then a Victim (an NPC with variables: health & isVictimDead) - MyVictim Blueprint

When Victim Health goes below 0,

  • I destroy the Actor(MyVictim),

  • I set VictimIsDead = True

Then HERO(the player) hits "E" key to Spawn a New Victim

  • if VictimIsDead Then Spawn New Victim

The problem is... when I destroy Victim. I cannot have the player able to spawn the victim again.

After Testing: If I do not destroy Victim, I can spawn another Victim.

I believe the variables that store (isVictimDead) in myVictim Blueprint is destroyed too when I Destroy Victim Instance.

So my question would be:

How does one manage a scenario when a NPC is killed and you need to check to see if isVictimDead, in order to spawn new one. I tried Blueprint Comms and Blueprint Interfaces, Cast To, etc but when Victim is destroyed it seems the Variable I use to check this is also destroyed, so I cannot find a way to check if the Victim was destroyed to do a Spawn.

Any insight would be greatly appreciated.

Product Version: Not Selected
more ▼

asked May 04 '14 at 11:23 PM in Blueprint Scripting

avatar image

146 32 48 54

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

1 answer: sort voted first

most typically you would run all your killing management code and then destroy it, once it is destroyed, it's gone, so it's typically the last thing you do when an enemy dies. If you want to only spawn 1 after it has died, why not store isVictimDead on the player instead. that way when the victim dies you still have access. But you would never want to ask a destroyed actor if it's dead, dead things don't talk back :)

If it was a little more large scale than just the one, there are many things that could manage this. for example, the enemy doesn't need to be destroyed to be invisible to the player. The actual enemy could be invisible and then reset and made visible when you press a key. You could also have some form of manager that keeps track of everyone. It really depends on the situation, scale and performance requirements that allow you to figure out which way to go.

For example, if you were making an npc that could be killed but always respawned, why destroy it at all? deleting and recreating things takes up a little performance on your computer it's far better (performance wise) to reuse what you already have. Some games have a big list (called a pool) of bullets, when one is out of range it gets flagged as being not in use, when someone shoots it grabs a not in use bullet and fires it, this boosts performance of consistently reallocating memory.

Well that's my ramble over, hope I have helped in some way

more ▼

answered May 08 '14 at 03:18 PM

avatar image

16 2 3 5

avatar image DreamBotStudios May 09 '14 at 04:35 AM

Thats makes total sense, it appears "I was speaking to dead people" ;-) No wonder they didn't respond... ha haha.. Thanks for the insight on using hidden instead of destroyed.

I am curious, have you noticed issues with Destroyed Actors on Standalone mode? I am finding in Standalone Mode I cannot call functions and spawn my character after being destroyed. I am using Blueprint Comms to call different functions in different blueprints, but not sure why I can call function in Editor, but not in standalone.

I am using a Mac and UE 4.1.0 Thanks

avatar image iveytron Jul 08 '14 at 03:06 AM

I second this approach, You can either wait to destroy the objects until you've reaped the info you want, or store the variable in some sort of information controller object

(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