Non-Static Variables

Non-static Variables in Watcher Mode

Non-static variables require a tad more care to be monitored in Jahro's Watcher Mode. Because they're not static, they are related to specific instances of a class, and Jahro needs to know exactly which instance you're referring to.

This is where the Jahro.RegisterObject() function steps into the spotlight. By registering an object, Jahro knows to which instance the non-static field or property belongs.

Here's how you do it:

public class PlayerController : MonoBehaviour
{
    [JahroWatch("Player Health", "The current health of the player", "Player Stats")]
    public int health;
 
    void Start()
    {
        Jahro.RegisterObject(this);
    }
}

In the example above, we have a non-static field health in the PlayerController class. To monitor the 'health' field of a specific player, we use the Jahro.RegisterObject function and pass this, which represents the current instance of the PlayerController.

With that, Jahro is able to track the health field of this specific player instance in real time. It will display this information in Watcher Mode under the 'Player Stats' group with the name Player Health.

Remember to only use Jahro.RegisterObject for objects that are pertinent to your current gameplay situation. Unnecessary usage can lead to clutter in your Watcher Mode.