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.

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 :slight_smile:

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

1 Like

Thats makes total sense, it appears “I was speaking to dead people” :wink: 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

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