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:
When Victim Health goes below 0,
Then HERO(the player) hits "E" key to Spawn a 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 :)
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
Follow this question
Once you sign in you will be able to subscribe for any updates here