How do I resurrect a dead character?

When a PC or NPC is killed using the BasicKilledReactor, several components are disabled and the ActorCore is set to “killed”. This disables collisions, processing, etc.

If you want to ressurrect the character, we need to reverse what the BasicKilledReactor did.

Lets assume we have a valid Motion Controller variable called “mMotionController”. In which case, we can do this:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
IAttributeSource lAttributes = mMotionController.gameObject.GetComponent<IAttributeSource>();
lAttributes.SetAttributeValue("Health", 120f);

mMotionController.enabled = true;
mMotionController.ActorController.enabled = true;
mMotionController.ActorController.AllowPushback = false;

mMotionController.ActorCore.IsAlive = true;

Collider[] lColliders = mMotionController.ActorCore.gameObject.GetComponents();
for (int i = 0; i < lColliders.Length; i++)
{
    lColliders[i].enabled = true;
}

if (mMotionController.ActiveMotion != null) { mMotionController.ActiveMotion.Deactivate(); }
mMotionController.ActivateMotion(typeof(BasicIdle));

In the code you can see that we do the following:

  1. Restore the health
  2. Re-enable the Motion Controller
  3. Re-enable the Actor Controller
  4. Set the Actor Controller to allow push back (assuming that was on originally)
  5. Set the Actor Core to alive
  6. Re-enable the colliders
  7. Disable the current Death motion (it runs continuously)
  8. Start the motion we want to resurrect them

In addition, any other settings you may have done when the character was killed may need to be reversed.

Finally, you may need to uncheck the “Remove Body Shapes” property on the BasicKilledReactor. By default, this property is checked and it will clear the character’s body shapes in order to stop processing. Either uncheck this option or re-create the body shapes when you bring the character back to life.

Put this code where ever you resurrect the character.

Leave a Reply