C#: Development with Unreal
Creating C# Classes
To explain how to achieve this in Unreal, follow this potential scenario:
Let's say we have a C# class that contains some variables and functions we want to use in Unreal:
namespace MyNamespace { public class MyClass { // This is a C# field public double MyDoubleField = 5.0; // This is a C# property public double MyDoubleProperty { get => MyDoubleField set => MyDoubleField = value * -1.0 } // This is a C# function public void LetsChangeMyDoubleValue() { MyDoubleValue += MyDoubleValue * 2.0; } } }
Now in Unreal, you can use the
Get MonoType
node andCreate Mono Object
node to create your C# object:- Make sure C# class, variables and functions are made public
- The name of your C# type is
<<NAMESPACE_NAMES>>.<<CLASS_NAME>>
The last step is to create a
weak
orstrong
reference to the C# object- Weak references are used when you want to point to a C# object that may exist or not - use
Create Mono Object Ref
node - String references are used when you want the C# object to exist for the entire duration of the level - use
Create Mono Object Pinned Ref
node
- Weak references are used when you want to point to a C# object that may exist or not - use
Note
We recommend you store your C# objects in a variable in the blueprint. This can be done by right-clicking on the output and hitting Promote to Variable
.
Other Mono Functionality
Currently, Nominal supports functionality around a C# Instance/Object since users may want to create custom classes that may not inherit from the NominalSystems
namespace. Below is a list of the blueprint nodes you can use with C# objects: