Skip to content

Using InspectMe in Your Unity Projects

Introduction

As a Unity developer, InspectMe empowers you to conduct deep inspections of your game objects and scripts. This tool is crafted to enhance your debugging experience, making it more insightful and efficient. Let's delve into how you can fully leverage InspectMe in your development workflow.

Basic Inspection

Info

For an in-depth overview of all the InspectMe methods and their usage, please refer to our Detailed Methods Guide.

Initiate inspections using the InspectMe() method in any class. This versatile method enables detailed examination of your Unity objects.

Key Points:

  • Awake Method: Avoid calling InspectMe() from the Awake method, as it won't be effective.
  • Accessibility: Inspect both private and public members without requiring [Serializable] or [SerializedField] attributes.
  • Build Safety: Like Debug.Log, InspectMe() is safe to include in builds. However, it's good practice to remove or comment it out once you're done debugging.
public class MyClass : MonoBehaviour
{
    void Start()
    {
        // Basic inspection of the current object
        this.InspectMe();
    }
}

Info

Just a heads-up: isn't compatible with every type. To get the most out of it, take a moment to look at our Supported and Unsupported Types.

Advanced Inspection Techniques

Custom Naming

When you have multiple instances of the same class, assign custom names to differentiate them in the Tree-View.

// Assign a custom name for easier identification
this.InspectMe("CustomInstanceName");

Inspecting Nested Properties and Expressions

Use InspectMe for in-depth analysis of nested properties and expressions across various development scenarios, extending beyond just UI elements to more intricate aspects of your project.

// Inspecting a nested property
uiElement.InspectMe(x => x.pivot);

// Inspecting a complex property
this.InspectMe(x => x.ComplexProperty);

Example:

public class EnvironmentController : MonoBehaviour
{
    private RectTransform uiElement;
    private float temperature;
    private float humidity;

    // Derived property
    public float ComfortIndex => (temperature + humidity) / 2;

    void Start()
    {
        // Inspecting a nested property
        uiElement.InspectMe(x => x.pivot);

        // Inspecting a complex property
        this.InspectMe(x => x.ComfortIndex);
    }
}

Dynamic Inspection with MemberInfo

Inspect properties determined at runtime using MemberInfo. This method is beneficial for properties that aren't known at compile-time.

// Dynamic property inspection
PropertyInfo propertyInfo = typeof(MyClass).GetProperty("PropertyName");
this.InspectMe(propertyInfo);

Example:

public class DynamicInspector : MonoBehaviour
{
    [SerializeField]
    private GameObject dynamicObject;

    void Start()
    {
        PropertyInfo dynamicProperty = dynamicObject.GetType().GetProperty("PropertyName");
        dynamicObject.InspectMe(dynamicProperty);
    }
}

Leveraging Watchers

Enhance your inspection by attaching watchers to your inspected members. Watchers notify you of real-time changes in values.

Adding Watchers

You can add a watcher right after your InspectMe() call. Customize the watcher's behavior with various parameters, like notification methods and activation settings.

Info

For a comprehensive guide on adding and configuring watchers, visit our Add Watcher Methods page.

Correct Usage of AddWatcher

// Basic watcher addition with notification type
this.InspectMe(x => x.myValue).AddWatcher(WatcherNotifications.Log);

// Using a callback with a watcher
this.InspectMe(x => x.myValue).AddWatcher(OnValueChanged);

// Callback example
private void OnValueChanged(int newValue)
{
    // Handle the value change here
}

Incorrect Use Cases for Watchers

Watchers are powerful but have limitations. Avoid using them in unsupported scenarios.

// 1- Adding a watcher with null callback or None notification
this.InspectMe(x => x.myValue).AddWatcher(null); // Null callback
this.InspectMe(x => x.myValue).AddWatcher(WatcherNotifications.None); // None notification

// 2- Adding a watcher to unsupported types
this.InspectMe(x => x.myClass).AddWatcher(OnClassChanged); // Not valid for classes/structs
For a comprehensive understanding of the types that Watchers can monitor, please refer to our detailed section on supported types by watcher.

Remember

Watchers are primarily for debugging purposes in the Unity Editor and should not be used for game logic in production.


For further assistance, don't hesitate to reach out to our support section.