Get SpatialOS

Sites

Menu

The SpatialOS Unreal integration is currently in beta. We’re very open to feedback - don’t hesitate to get in touch on the forums if you have any thoughts.

Creating entity blueprints

In order to connect the world that an Unreal worker sees to the game world that SpatialOS manages, you need to connect SpatialOS entities to Unreal blueprints.

To tell an Unreal worker which blueprint to use to represent an entity in the world, you specify something called an “entity type” for each entity. You need to do this when you add an entity to the initial state of your world, and when you create an entity.

To create a new type of entity in your world, you need to:

  1. Create an entity blueprint.
  2. Add the components you want the entity to have to the blueprint.
  3. Create the entity, or add it to the initial state of your world.

    You must use the exact name of the blueprint as the “entity type”.

Create an entity blueprint

All blueprints for entities must be in the EntityBlueprints folder, in the the root Content folder (which you can navigate to from the Content Browser in the Editor).

When you create an entity blueprint, you have the following options:

You could also have some logic in C++, and some in the child blueprint, to avoid doing things in blueprints that are easier to do in C++.

Blueprint-only

To create a blueprint-only entity blueprint:

  1. In the Editor, in the Content Browser, navigate to the EntityBlueprints folder located in the root Content folder.
  2. Right-click inside the folder, and select Blueprint Class under the heading Create Basic Asset.
  3. As the parent class, select either Actor or a class that inherits from Actor (such as Pawn or Character).
  4. Give the blueprint the name that you want to use as the “entity type”.

Creating blueprint

C++ class

To create a C++ class for an entity blueprint:

  1. In the Editor, in the Content Browser, navigate to the C++ classes folder located in the root Content folder.
  2. Right-click inside the folder and select Create C++ class.
  3. As the parent class, select either Actor or a class that inherits from Actor (such as Pawn or Character).

    Creating C++ class

  4. Navigate to the EntityBlueprints folder located in the root Content folder.

  5. Right-click inside the folder and select Blueprint Class under the heading Create Basic Asset.

  6. Select the C++ class you just created as the parent.

  7. Give the blueprint the name that you want to use as the “entity type”.

    Sorting out blueprint

Add components to an entity blueprint

SpatialOS components define all the data associated with an entity. Read more about components.

For information on deciding what components your entity should have, see Designing components.

You can add components to your entity blueprint:

Note that you’ll also need to add the same components to the entity template when you create the entity. See the section on Creating an entity for details.

Add components in blueprints

To add SpatialOS components to a blueprint-only entity blueprint:

  1. In the Content Browser, navigate to the EntityBlueprints folder.
  2. Select and double-click the blueprint that you’d like to add a component to.
  3. Make sure that the generated code for your Unreal project is up to date by running spatial codegen.

    This will generate a UActorComponent for each component defined in your schema.

    You can attach these to your entities’ Actor blueprints, and use them to interact with the corresponding SpatialOS component on the corresponding entity. See [Interacting with entity components](/reference/12.0(/reference/12.0/unrealsdk/interact-with-world/interact-components) for details.

  4. The blueprint Editor will appear. Select Add Component in the Components panel.

  5. In the search field, start typing the name of your SpatialOS component. The suggestion box should have an ActorComponent named {name of the component}Component for each SpatialOS component defined in your schema.

    Sorting out blueprint

Add components in code

To add components in code:

  1. Find the parent C++ class of your blueprint that you created, and open it in Visual Studio.
  2. Open the header file. Under private:, declare a member variable for your component. For example:

    UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Character", meta = (AllowPrivateAccess = "true"))
    class UTransformComponent* TransformComponent;
    

    Note: The class prefix is a forward declaration, so you don’t need to include the header file TransformComponent.h in this file.

  3. Under public:, add a getter function:

    FORCEINLINE class UTransformComponent* GetTransformComponent() const
    {
        return TransformComponent;
    }
    
  4. Open the implementation file of your C++ class. In the constructor, initialise the component:

    TransformComponent = CreateDefaultSubobject<UTransformComponent>(TEXT("TransformComponent"));
    
  5. Include the necessary header file at the top of this file:

    #include "Improbable/Generated/cpp/unreal/TransformComponent.h"`
    

What’s next

Create the entity, or add it to the initial state of your world.

Was this page helpful?

Thanks for letting us know!

Thanks for your feedback

Need more help? Ask on the forums