Creating a Unity-based simulator

Note: This tutorial has been tested for Unity version 2022.3

In this tutorial, we’ll use the Unity game engine to create a simple, not-so-fancy simulator that serves as a barebones boilerplate for Unity-based simulators prepared for distributed simulation using the Inhumate RTI.

You’ll create a simple “walking simulator” where the player can move around using W, A, S, and D, drop boxes, and interact with the physics engine. Not exactly an exciting player experience, but it is a straightforward way to structure the project to take advantage of Inhumate Suite features. The simulator will support recording, playback, co-simulation (multiplayer), and much more.

Setup the project

Create a new Unity project and prepare it with the Inhumate RTI Unity integration package.

Note: To complete this section you will need Nodejs 18 or above.

  1. Create a new Unity project using the Core 3D (Built-In Render Pipeline) template.

  2. Add the Inhumate RTI Unity integration package to your project using the OpenUPM command-line tool:

     # Install openupm-cli
     npm install -g openupm-cli
    
     # Go to your unity project directory
     cd YOUR_UNITY_PROJECT_DIR
    
     # Install package: com.inhumatesystems.rti
     openupm add com.inhumatesystems.rti
    

Verify that the package has been added in your project folder under Packages.

Create the environment

In this section, we’ll create a simple enclosed arena to serve as the playing field and an interactive box prefab.

  • Rename the current scene (optional) to Demo.
  • Make a square “arena” by using a plane and cubes. See image below for reference.
  • Create a Rigidbody cube and name it Box. Save as prefab and remove.

    Arena example

Create the player

Next, we’ll set up the player and enable basic movement and spawning of boxes.

  1. Create a Rigidbody capsule and name it Player.
  2. In the inspector, scroll down to the Rigidbody component. Set Mass, Drag, and Angular Drag all to 10. Freeze X and Z rotation in Constraints.
  3. Add a camera as a child in the player object. This will be your point of view when playing. Adjust it to your liking and make sure it has higher Depth than your scene camera.
  4. Make a simple player controller script that moves the player with W, A, S, and D and instantiate the cube prefab by pressing B.

    Start by adding your members and initialize your rigidbody:

     public float force = 1000f;
     public float torque = 50f;
     public float cubeSpawnDist = 3f;
     public new Camera camera;
     public GameObject boxPrefab;
    
     Rigidbody rb;
    
     // Start is called before the first frame update
     void Start()
     {
         rb = GetComponent<Rigidbody>();
     }
    

    Add the FixedUpdate() function and add your code for the player movement:

     void FixedUpdate()
     {
         // Forward / Backward movement
         if (Input.GetKey(KeyCode.W))
         {
             rb.AddForce(transform.forward * force, ForceMode.Force);
         }
    
         if (Input.GetKey(KeyCode.S))
         {
             rb.AddForce(-transform.forward * force, ForceMode.Force);
         }
    
         if (Input.GetKey(KeyCode.A))
         {
             rb.AddTorque(0, -torque, 0);
         }
    
         if (Input.GetKey(KeyCode.D))
         {
             rb.AddTorque(0, torque, 0);
         }
     }
    

    And instantiate your box prefab in Update():

     void Update()
     {
         // Instantiate boxprefab when pressing B, cubeSpawnDist units from the player
         if (Input.GetKeyDown(KeyCode.B))
         {
             Instantiate(boxPrefab, transform.position + transform.forward * cubeSpawnDist, Quaternion.identity);
         }
     }
    
  5. Attach the script and add your box prefab. Try playing the scene. Move around, drop boxes and interact with them while being constrained by the arena.

At this point, the player, boxes, and arena are set up. You can now explore the basic features of the Inhumate Suite in this environment.

Add RTI components

Let’s add some components from our RTI Unity integration package and then look at the results in Inhumate Viewer.

Note: These components determine how objects are represented in the Viewer and handled in the RTI. Feel free to change the values to suit your needs.

  • Add RTI Static Geometry component to the arena walls and floor.

    arena_components

  • Add RTI Entity and RTI Position components to the player. Set the Type and Size properties.

    player_components

  • Add RTI Entity and RTI Position components to the box prefab. Set the Type and Size properties.

    box_components

Start Inhumate Viewer. When you run the project, you should see the player and the arena in the 3D tab in the viewer.

viewer

Support runtime control and scenario loading

Now we’ll prepare the project for runtime control and scenario loading using the RTI by creating a new scene and some configuration.

  1. Create a new scene and call it Home.
  2. In the new scene, create an empty object and add the RTI Connection component.
  3. Create a RTI scenario in the project window and type the name of the previous “arena” scene in Scene Name.

    scenario

  4. Add the scenario in the RTI Connection component in your Home scene.

    connection

  5. Add both scenes in your build settings.

Now, if you run the project from your Home scene, you should be able to select your scenario and press Load from the runtime control in Inhumate Viewer. Your Demo scene has now loaded. Press Start and run around, spawn and interact with boxes and see the viewer mirror your actions. Try the other controls: Pause, Stop, and Reset.

Add the runtime control panel

If you want to access the runtime controls from your Unity scenes, you may add the RTIRuntimeControlPanel prefab from the package to your scenes. Create a Canvas and add the prefab.

control_panel

Support playback and co-simulation

To support playback and co-simulation, the scene needs an RTI spawner that dynamically adds entities (the player and spawned boxes).

  1. Save the player as a prefab and remove it from the scene. Spawning will be handled by the RTI spawner.
  2. Create a copy of the player prefab with the controller script excluded. Name it PlayerPlayback. This object will act as a “remote representation” during playback, ignoring any inputs.
  3. Create an empty object in your Demo scene and add the RTISpawner component.
  4. Create multiple empty objects and place them around the arena. These will act as spawn points.
  5. In the spawner component, add the box and player playback prefabs in Spawnable Entities.
  6. Add the RTIUnknownEntity prefab from the package to Unknown Prefab.
  7. Specify the player prefab and add the player spawn points.

    spawner

With this setup, you are ready to test playback and co-simulation using Inhumate Recorder.

  • Load a scenario, press Start, play for a bit, then press Stop followed by Play.
  • Replay earlier recordings using the three dots menu and selecting Play.
  • Run another instance of the project to test co-simulation and verify you can see the other player.

Conclusion

You have now completed the basic setup for integrating the Inhumate Suite with a Unity project. Playback and co-simulation should be working, and you are ready to continue experimenting with additional features and configurations.


Copyright © Inhumate AB 2026