Table of Contents

Custom Components: Creating the Object Blueprints

Creating a C# Blueprint

Once the DLLs have been compiled, Nominal Editor can be relaunched, which will load in the DLLs correctly. Starting with the Solar Panel, a new blueprint class will be created. This will be created inside the tutorial folder for this purpose inside Tutorial_04_CustomComponents. For the solar panel class, a new blueprint class should be created and be of the type SolarPanel. It will be named BP_ExampleSolarPanel. The name does not need to match the C# name, but by convention, it should be close to it.

Untitled

Note

It is best practice to inherit the C++ class as the same one as the C# class that was inherited from. The example solar panel class inherits from SolarPanel, as should the blueprint class. This is the class name with no BP or NS acronyms attached.

Using the C++ classes as a parent will result in a mesh-less class. When the blueprint is opened, there will be no assets or meshes associated with the class. These will be added in the next step. The object will look empty and the pink square and axis will indicate where the local origin is.

Untitled

The important part about connecting the class to the C# one is located in the Physical Object section of the details panel. Select the top-level object in the component tab and navigate to Nominal SystemsPhysical Object. There is a field called Mono Type Name which specifies the C# class that this object will be connected to. Since this class inherits from Solar Panel, the default one will be found there. Instead, change the type name to Editor.ExampleSolarPanel. This must match the namespace and the class name of the class that is being inherited.

Warning

Nominal Editor is configured such that if the class name is invalid, spelt incorrectly or is not updated in the DLLs, the program will throw errors and could crash. Make sure to double-check that the namespace and class names are correct and valid. Ensure that the parent C++ class of this object also matches the parent C# class written in the solution.

Additional socket information can be provided which allows the class to be exported to Nominal Studio and used there. Information on how to do this will not be covered in this tutorial, but the Package Information can be entered.

Untitled


Creating the Solar Panel

Now that the object information is created, the next step is to add in the mesh. In the components tab on the left side of Unreal, click Add Component and find Static Mesh. Add this component to the solar panel. Once added, select the mesh and in the details, the object and material for the mesh can be applied. Searching ‘solar panel’ will provide some options for this panel. For Nominal Editor objects, it is also best practice to change the location of the mesh such that the centre of mass is located at the origin. In this case for the Obj_SolarPanel_1U_XY, that location is \((-5.0, 6.0, 0.0)\), where the units are in centimetres.

Untitled

The solar panel has one public parameter that needs to be set on the C# object. This is the EfficiencyScale parameter. This will need to be created as a variable on the solar panel. Add a new variable with the same name as a float in the blueprint tab. Make sure to set Instance Editable and Expose On Spawn, as these will ensure that the variable can be set when spawning the solar panel. A default value can also be provided.

Untitled

Note

The Mono system will not automatically create variables for you in Unreal. You will be required to manually create and connect up C# parameters to the custom components.

Once added, head to the Event Graph of the component blueprint (not the level blueprint) and on the Event BeginPlay event, the C# parameter for the variable needs to be set. This can be done using the Mono functions. First, fetch the Mono object reference using the Get Mono Object (Interface Call) method. This will return the Mono object structure containing the exact pointer to the object in the runtime that is created. Then, use the function Set MonoProperty (Float) to set the value of the scale to the value within the Unreal variable. This ensures that the Unreal and C# values for this property are synced up.

Untitled

Warning

Although the name of the Unreal variables does not matter, the name of the Mono variables does. Make sure the spelling of the property name is the same as the C# solution. The variables are case-sensitive.

The last function to add is the ability to fetch the TotalEnergy parameter from the solar panel. As this is not an initialization parameter but rather a value that is calculated, this is not done in the same way. Instead, a new function is created called GetTotalEnergy in the Unreal object. The object needs to have a return type of float and should be made to be pure. Pure functions will ensure they can be called without a direct execution pin. Similar to the previous function, the Get MonoProperty (float) can be used here to return the value of the C# variable.

Untitled


Creating the Thermal Sensor

The next component to replicate is the thermal sensor. This can be done in the same way, except the base class for the thermal sensor should be Sensor. This one will be called BP_ExampleThermalSensor. As with the previous example, the Mono information should be updated such that the class name is Editor.ExampleThermalSensor.

Untitled

A mesh can also be added. Since there are no objects for a thermal sensor provided, the Obj_IMUSensor object will be selected. It will also be moved so that the centre of mass is at the origin, which has the coordinates of \((-2.5, 4.0, 0.0)\).

Untitled

The thermal sensor requires two input parameters; NoiseMean and NoiseSigma. Both of these parameters are floats and can be created in the same way as the solar panel above. The parameters must be exposed on spawn and can be connected to the Mono runtime using the Set MonoProperty (Float) functions on the Event BeginPlay event in the event graph.

Untitled

Finally, the only parameter that needs to be returned from the object is the thermal message. In C#, this was named Out_ThermalMsg. Messages cannot be created as Unreal classes in this current version, but the object reference can still be returned as used as objects. A function should be created here that is called Get Thermal Message and returns the object reference for the message using Get MonoProperty (Object).

Untitled