Game Object Logger

Overview

The Game Object Logger is a MonoBehaviour that wraps logging functionality. The ideal use cases for this logger are for complex Game Object with several components that benefit from specific logging needs.

For example, the Player object often contains several scripts. These can reference a GameObjectLogger, making use of specific Logger Settings.

Configuring

Being a Unity component, setting this logger up is straight forward. In the selected game object, add a new GameObjectLogger script:

In the Logger Settings field, assign an existing Logger Settings:

Note: Read more into how to create and configure a Logger Settings instance here.

Using

Once the GameObjectLogger is configured, it can be called in any script from this GameObject with the following code:

private GameObjectLogger _gameObjectLogger;

void Awake()
{
    _gameObjectLogger = GetComponent<GameObjectLogger>();
}

Note: Although it's dependent on the developer, it's advisable to keep this GetComponent call in the Awake method, so that logging is available in the Start method, if required.

To perform a logging call, reference the GameObjectLogger and call its Log method:

_gameObjectLogger.LogDebug("Logging a debug message.");

Last updated