Basic question about using third party packages

I’m using UFPS in my FPS game.
UFPS has a class vp_DamageHandler. It’s attached to my target. Inside this class, there’s:

public virtual void Die()
{
dieFunctionCalled = true; //the only thing I've added to this class, besides declaring dieFunctionCalled
...some UFPS code...//among other things, this is where the object is destroyed or deactivated
}

I want to keep the original files as clean as possible. I want to do my own coding in a different script to keep things tidy.

I want to do some other things when the target dies, so I’ve added myScript to my target as well, and tried this:

void Update () {
        if (GetComponent<vp_DamageHandler> ().dieFunctionCalled) {
            GetComponent<vp_DamageHandler> ().dieFunctionCalled = false;
            Debug.Log ("dieFunctionCalled");
        }
}

The problem is that the target is destroyed before the dieFunctionCalled is set to true. So the moment the target dies, myScript is deactivated and doesn’t log “dieFunctionCalled”. If I would respawn the target, the dieFunctionCalled does show up in the console.

I’ve tried attaching myScript to a empty GameObject, but than I get

Anyone who can help me with this? I’m new to Unity. Basically, all I want is to keep the original UFPS files as clean as possible, and write all my scripts in a different file.

The reason you get the error when you attach to another gameobject is because GetComponent without a target always looks on the same object for the component. So, of course it can’t find the vp_DamageHandler script because it doesn’t exist, so you get that error.

Die is also a virtual method which means you can override it which would allow you to declare your own code. I don’t know when the object is being destroyed, but you can execute your own code and then execute the base ufps code after. Just look up override with virtual if you haven’t ever used it.

Thanks for your reply. I’ve resolved this issue by using the EventManager.