Table of Contents

C#: Component

A Component represents a environmental object or physics object that interacts with it’s parent in the simulation. It is the base for all sensor, thermal, power, dynamics or custom modules in a simulation. Components can be attached to other components if OnChildTypeSupported function returns true.

Warning

All child components run their OnUpdate function before it’s parent OnUpdate is called.


How do I create a Component?

When you create a new C# class, make sure you inherit from NominalSystems.Core.Component. This is the base class for the component. However, typically, components added in Editor.CSharp may inherit from classes with more functionality instead. This is for a base component class with no simulation functionality.

using NominalSystems.Core

public class MyComponent : Component
{
    // ...Your code goes here...
}

How do I add a new Component?

In C# you can create components either in a SimulationSystem or as a child in a Component. This can be done with the Add{T}() function which will add a component as a child or add a component to the simulation. These functions only work if the class inherits from one of the types below:

  • NominalSystems.Core.Component
  • NominalSystems.Core.SimulationSystem
using NominalSystems.Core

public class MyComponent : Component
{
    public MyChildComponent CreateChildComponent()
    {
        // This will create a child of 'MyComponent' in the simulation
        // 'MyChildComponent.OnUpdate' will run before 'MyComponent.OnUpdate'
        return Add<MyChildComponent>();
    }
}

public class MySimulationSystem : SimulationSystem
{
    public MyComponent CreateComponent()
    {
        // This will create 'MyComponent' in the simulation
        // 'MyComponent' has no parent component attached to it
        return Add<MyComponent>();
    }
}