📓
Nez framework documentation
  • Nez Setup
  • Nez Core
  • Scene-Entity-Component
  • Rendering
  • Content management
  • Dear IMGUI
  • Physics
  • Farseer physics
  • Verlet physics
  • Entity Processing Systems
  • Deferred lighting
  • Nez UI
  • Pathfinding
  • Runtime Inspector
  • Svg Support
  • AI (FSM, Behavior Tree, GOAP, Utility AI)
  • Links
Powered by GitBook
On this page
  • Exposing Properties and Fields in the Inspector
  • Exposing Methods in the Inspector
  • Tooltips
  • Extending the Inspector

Was this helpful?

Runtime Inspector

PreviousPathfindingNextSvg Support

Last updated 5 years ago

Was this helpful?

Nez includes some really handy runtime and inspection facilities. You can access the inspector by opening the (via the tilde key) and then using the inspect command. Out of the box the inspector can inspect the following types: int, float, string, bool, enum, Color, some structs, subclasses and . When you use the inspect command you can either pass in an Entity name or pp, the latter will inspect all the PostProcessors in the Scene.

With non-US keyboard, you may not be able to open debug console via tilde key. Then, you may want to change .ConsoleKey.

Exposing Properties and Fields in the Inspector

[Inspectable]
string myPrivateField;
[Range( 0.1f, 100 )]
float groundAccel;

// the third, optional parameter lets you specify the sliders step value
[Range( 0.1f, 100, 5 )]
float airAccel;

Exposing Methods in the Inspector

The inspector also has the ability to expose a button to call methods. Methods must have 0 to 1 parameters and if they have a parameter it must be of type int, float, bool or string. To expose a method in the inspector add the InspectorCallable attribute to the method. An example is below:

[InspectorCallable]
public void DoSomething()
{}


[InspectorCallable]
public void DoSomethingWithParameter( bool isDone )
{}


[InspectorCallable]
public void ThisWontWorkBecauseItHasTwoParameters( bool isDone, int stuff )
{}

Tooltips

You can add tooltips to the inspector via the TooltipAttribute. Tooltips will appear when you hover over the label for an inspected field.

[Tooltip( "Acceleration when on the ground" )]
float groundAccel = 1.0f;

Extending the Inspector

You can display any custom types in the inspector as well by writing your own custom inspectors. You can do this by adding the CustomInspector attribute on the class that you want to make a custom inspector for (YourClass in the example below). The attribute takes in a single parameter which is the Type of the Inspector subclass that manages the UI for the class (YourClassInspector in the example). Note that the Inspector subclass is wrapped in #_if/#_endif so that it is only compiled into debug builds.

The Inspector class provides several helpers to assist with making custom inspectors. It will cache access to the getter/setter for the field/property for easy access. It wraps access to the getter/setter via the GetValue and SetValue methods which are generic and take care of casting for you. If you want to add your own custom attributes on the field/property they are accessible via the GetFieldOrPropertyAttribute generic method.

[CustomInspector( typeof( YourClassInspector ) )]
public class YourClass
{
    bool _isBlue { get; set; }
    float _friction;
    // the rest of your class
}


#if DEBUG
public class YourClassInspector : Inspector
{
    // this is where you setup your UI and add it to the table
    public override void Initialize( Table table, Skin skin )
    {}

    // this is where you update the UI
    public override void Update()
    {}
}
#endif

By default, the will display any public properties/fields that are of a supported type. It will also check Materials for non-null Effects and it will display any valid properties from the Effect. The inspector can also display private fields/properties by just adding the Inspectable attribute:

Int and float fields/properties can optionally be displayed with a slider by adding the Range . Note that you do not have to add both the Inspectable and Range for private fields/properties. Just the Range attribute is enough to let the inspector know you want it displayed.

inspector
attribute
attributes
Entity
PostProcessor
debug console
Effect
Transform
DebugConsole