Extending Opsive code

grkwasniewski

New member
Hi all,

quick question. Without going into technical details, I would like to expose a new public field on the Health component. So I'm adding something like this:

[Tooltip("Any object that should spawn when the object dies from receiving heavy damage.")]
[SerializeField] protected GameObject[] m_SpawnedObjectsOnOverPowerDeath;

public GameObject[] SpawnedObjectsOnOverPowerDeath { get { return m_SpawnedObjectsOnOverPowerDeath; } set { m_SpawnedObjectsOnOverPowerDeath = value; } }

But this field won't show in Unity editor. How can I extend the Opsive implementation?
 
This is because the Health component (as with most Opsive components) has a custom inspector, HealthInspector. Your two options are:

1. Extend HealthInspector to display your new properties.
2. Instead of extending Health directly, sub-class it and add your own properties, override methods, etc.

I would highly recommend #2. If you choose #1, you should make sure to keep track of which parts of the base scripts are yours, so that if you ever update UCC in the future, you don't overwrite them and lose your changes. (I do this in a project of mine by wrapping code changes in comment tags.)
 
Top