# Tutorial

In this short tutorial we are creating a small Digital Twin model with a source, a conveyor and a light barrier.

The needed 3D components are already available. If you would like to use own 3D data, you would need to import the 3D data from your CAD system using [CADLink](https://doc.realvirtual.io/basics/cad-import/cadlink) (included in realvirtual.io) or another suitable solution like for example [Unitys PIXYZ](https://unity.com/de/products/pixyz).

### Create a new scene

You should always create your models outside the *realvirtual* folder. This is because if you import a new Version of realvirtual.io, you would not like to destroy what you did. If you keep your scripts outside the realvirtual.io folder this will enable you to update your model with new releases of realvirtual.io without problems.

First create a new folder. We will call this folder *Tutorial*. Select assets and right click *Create > Folder*. Select the folder, hit F2 and name it to *Tutorial*.

<figure><img src="https://260262196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FpYxFg97YnJX96UzNNTSd%2Fuploads%2Fgit-blob-43d7b839899eac9c4b8da70b01cae37d078f2974%2Ftutorial-folder.png?alt=media" alt=""><figcaption><p>Create a new Tutorial folder</p></figcaption></figure>

For creating a new scene, select *Tools > realvirtual > Create new realvirtual scene*

<figure><img src="https://260262196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FpYxFg97YnJX96UzNNTSd%2Fuploads%2Fgit-blob-5f61b400a4d86f997e21662ab70eb0e78ab31615%2Frvnewscene.png?alt=media" alt=""><figcaption><p>Create a new scene</p></figcaption></figure>

After the scene is created, please save it with *File > SaveAs* in your Tutorial folder with the name *tutorialmodel*:

<figure><img src="https://260262196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FpYxFg97YnJX96UzNNTSd%2Fuploads%2Fgit-blob-053697df6c090158f5b2b73369b7973c81281c4d%2Ftutorial-tutorialmodel.png?alt=media" alt=""><figcaption><p>Saved new scene in the Tutorial folder</p></figcaption></figure>

You should now have an empty scene with a base plate and some lights:

<figure><img src="https://260262196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FpYxFg97YnJX96UzNNTSd%2Fuploads%2Fgit-blob-d6ab099e3ff2b9366ad6a9300af79aa82bdcb1ef%2Ftutorial-emptyscene.png?alt=media" alt=""><figcaption><p>Empty scene</p></figcaption></figure>

{% hint style="info" %}
You can hide the big lights and camera gizmos by setting the Gizmo size to 0 (see above picture).
{% endhint %}

You could also create a totally empty standard Unity scene and add the realvirutal component(before 2022 game4automation component) by *Tools > realvirtual > Add Object > realvirtual* in the Main menu.

{% hint style="info" %}
The realvirtual component provides some basic lights, mouse navigation in the deployed Digital Twin (Game view) as well as all standard settings and the standard [Runtime UI](https://doc.realvirtual.io/basics/runtime-ui).
{% endhint %}

### Starting your first scene

You can now start your first scene by pressing on Play in the top of the Unity UI.

Game view will automatically open and you can see the RuntimeUI as well as an empty model with just the base plate:

<figure><img src="https://260262196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FpYxFg97YnJX96UzNNTSd%2Fuploads%2Fgit-blob-775ccfa61c16883e3fe5b22aa0f4e9323e7af28f%2Ftutorial-playscene.png?alt=media" alt=""><figcaption><p>Playing the empty model</p></figcaption></figure>

### Insert the conveyor

Next we insert a 3D component. For the tutorial we use a prepared one, which is already used by the demo model. Select the conveyor under *Assets > realvirtual> 3DPfefabs > ConveyorSmall* and drag it into the scene. Place it somewhere in the middle of the base plate.

You can move the conveyor with the gizmo, which is visible as long as the conveyor is selected. Or you put in 0,0,0 into the Transform Position property. This will place the zero point of the conveyor onto the world zero point (which should be also the middle of the base plate):

<figure><img src="https://260262196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FpYxFg97YnJX96UzNNTSd%2Fuploads%2Fgit-blob-6e512129fb8fa65ba645c3001bb1b65aa251d551%2Ftutorial-placedconveyor.png?alt=media" alt=""><figcaption><p>Placed conveyor into the empty scene</p></figcaption></figure>

### Unpacking the Prefab

The conveyor belt that you have inserted into the scene is what is called a *prefab*. A *prefab* is a type of template and can be a very simple or a very complex component. A *Prefab* can be used multiple times in one or more scenes. As long as the embedded instances of the prefabs are not "unpacked" in the scene, they are still associated with the *Prefab* and inherit any changes to the prefab itself. For more information on the Unity Prefab System, see the Unity documentation here: <https://docs.unity3d.com/Manual/Prefabs.html>.

For the Tutorial, we should Unpack the *Prefab* instance completely and cut all dependencies to the original *Prefab*. Please select *ConveyorSmall* in the scene and with the context menu select *Prefab > Unpack Completely:*

<figure><img src="https://260262196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FpYxFg97YnJX96UzNNTSd%2Fuploads%2Fgit-blob-f5a040f34a6faf9954a515e17b853f4b5966cb9a%2Ftutorial-prefab.png?alt=media" alt=""><figcaption><p>Unpacking a prefab</p></figcaption></figure>

### Delete realvirtual.io components from conveyor

{% hint style="success" %}
This step is optional. The conveyor prefab is already equipped with some realvirtual.io components. But we would like to show you in this tutorial the full workflow. Like it would be without anything prepared - based on imported 3D objects.

This is why we are deleting the components and add them later on again. You could also skip this step if wished and continue with Insert a source.
{% endhint %}

Remove the component *Drive* on the object *ConveyorSmall* and also remove afterwards the *Rigidboy* on the object *ConveyorSmall*:

<figure><img src="https://260262196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FpYxFg97YnJX96UzNNTSd%2Fuploads%2Fgit-blob-36e755db1e34d23b2c0be5ffcbc1a67e3edc73e9%2Ftutorial-removecomponent.png?alt=media" alt=""><figcaption><p>Remove the component Drive</p></figcaption></figure>

\
Next delete *Transport Surface*, *Box Collider* and *Rigidboy* on *ConveyorSmall.Conveyor.Conveyor.*

\
You learned how to remove scripts from objects ;-). **You now removed everything what is prepared and we will add these needed scripts again in this tutorial.**

### Define the transport surface

{% hint style="success" %}
We now have an empty 3D component. No kinematic and physical behavior is defined yet. This is what a component would look like after the CAD import. CAD systems do not contain any information other than the structure and geometry. This means that we have to define all mechatronic behaviors like drives and sensors in realvirtual.io.

Unfortunately, until now there is no standard format for exporting extended information from the CAD system. However, our [Open Digital Twin Interface](https://doc.realvirtual.io/advanced-topics/page-5) allows you to develop your own exporter for the CAD system.t.
{% endhint %}

First we need to add a *Transport Surface* to the conveyor. For doing that we select the component *ConveyorSmall.Conveyor.Conveyor*. We select in the main menu *Tools > realvirtual > Add Script > Transport Surface* or we drag and drop the script *TransportSurface* under *Assets>realvirtual* onto *ConveyorSmall.Conveyor.Conveyor*.

A very easy way is, to use the [QuickEdit](https://doc.realvirtual.io/user-interface#quickedit) for adding the [*TransportSurface*](https://doc.realvirtual.io/components-and-scripts/motion/transportsurface)*:*

<figure><img src="https://260262196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FpYxFg97YnJX96UzNNTSd%2Fuploads%2Fgit-blob-dbc61988adaf5e7ef404bb88964bac297671db53%2Ftutorial-adddrive.png?alt=media" alt=""><figcaption><p>Adding a TransportSurface to the conveyor with QuickEdit</p></figcaption></figure>

{% hint style="info" %}
The Quick Edit overly buttons can be opened by pushing **F1** inside the scene view.
{% endhint %}

### Insert a Drive

We now insert a [Drive ](https://doc.realvirtual.io/components-and-scripts/motion/drive)on the Conveyor. We place it on the same component as the [*TransportSurface* ](https://doc.realvirtual.io/components-and-scripts/motion/transportsurface)before.

Select the *ConveyorSmall.Conveyor.Conveyor* component in your Scene and select in the main menu *Tools > realvirtual > Add Script > Drive* :

Alternatively you can also drag and drop the *Drive* Script under *Assets > realvirtual> Drive* onto the Inspector window of *ConveyorSmall.Conveyor.Conveyor*.

Or as before you can also use the QuickEdit Overlay Window.

And as a 3rd option you could also use *Add Component* on the Inspector window and than type in [*Drive* ](https://doc.realvirtual.io/components-and-scripts/motion/drive)and select the filtered script to assign it to the 3D component.

Your model should now look like this:

<figure><img src="https://260262196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FpYxFg97YnJX96UzNNTSd%2Fuploads%2Fgit-blob-e96879003b5839394d185d6d20454d0e34d79926%2Ftutorial-drivetransportsurface.png?alt=media" alt=""><figcaption><p>Added Drive and TransportSurface to the conveyor</p></figcaption></figure>

{% hint style="info" %}
Please remember. Most times you can add scripts on 3D components in 4 ways

* With the main menu
* By dragging and dropping it from the Assets folder *Assets>game4automation*
* by using *Add Component* in the *Inspector window*
* *or by using the QuickEdit overlay*
  {% endhint %}

### Defining the transport direction and turning the Drive on

Next we define some properties of the [Drive ](https://doc.realvirtual.io/components-and-scripts/motion/drive)within the Inspector window. Please also check if the Direction is set to *Linear X* (so that the shown transport direction is forward).

Please check, that the [*TransportSurface* ](https://doc.realvirtual.io/components-and-scripts/motion/transportsurface)is assigned to the [Drive](https://doc.realvirtual.io/components-and-scripts/motion/drive), which usually is done automatically. Set ***JogForward*** to ***True*** and ***TargetSpeed*** to ***300***.

<figure><img src="https://260262196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FpYxFg97YnJX96UzNNTSd%2Fuploads%2Fgit-blob-e0413429f4d0a62afaf4425c7f4fad6fc8b9fafe%2Ftutorial-driveproperties.png?alt=media" alt=""><figcaption><p>Changing the inspector properties of the Drive</p></figcaption></figure>

This settings will automatically start the [Drive ](https://doc.realvirtual.io/components-and-scripts/motion/drive)when the simulation is starting.

### Insert a source

A Source is automatically creating new components based on itself (what is called "spawning" in Unity).

Please select *Assets > realvirtual> 3DPrefabs > Can* and drag and drop it into the scene. Place the can at the beginning and on top of the conveyor.

Another way for creating the "standard" can source is to select the *TransportSurface* within the scene and to press **INS** on the keypoard.

Your model now looks like this:

<figure><img src="https://260262196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FpYxFg97YnJX96UzNNTSd%2Fuploads%2Fgit-blob-3141d28fca11905a494ff72bb3ec6aac50ef81b4%2Ftutorial-source.png?alt=media" alt=""><figcaption><p>Added source to the conveyor</p></figcaption></figure>

Please move the source to the beginning of the conveyor.

### Test the conveyor

Now we can test the conveyor. Start the simulation with the Unity *Play* button.

<figure><img src="https://260262196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FpYxFg97YnJX96UzNNTSd%2Fuploads%2Fgit-blob-320c79a622811aad4d52306fecdb4ac508849b36%2Ftutorial-startingmodel.png?alt=media" alt=""><figcaption><p>Your first Digital Twin - a conveyor with the source</p></figcaption></figure>

You might see that the texture on the conveyor is not moving in the right relation and the right direction. You need to set the texture scale yourself. Please select the *TransportSurface* and enter a *-2* into property *Texture Scale.*

### Insert a Sensor

As a last step we would like to place a [*Sensor* ](https://doc.realvirtual.io/components-and-scripts/sensors/sensor)(light beam) at the end of the conveyor.

Please create an empty *GameObject* into the Scene by selecting *GameObject > Create Empty* or by selecting ![](https://260262196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FpYxFg97YnJX96UzNNTSd%2Fuploads%2Fgit-blob-1f00468dd7a669719fabc7d20ec7a155d6c51c1a%2Ftutorial-empty.png?alt=media)on the QuickEdit overlay. If your new GameObject is added as a child please drag and drop it to the top level in your model. Rename the new GameObject to *Sensor*.

Next select *Tools > realvirtual > Add Component > Add Sensor* or select *Sensor* on the QuickEdit overlay.

Last but not least you need to move the *Sensor* GameObject to the end of the *TransportSurface*.

Your model now looks like this:

<figure><img src="https://260262196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FpYxFg97YnJX96UzNNTSd%2Fuploads%2Fgit-blob-9153fb106f2b6e373117104856c303563ae2b6ac%2Ftutorial-sensor.png?alt=media" alt=""><figcaption><p>Added Sensor to the end of the TransportSurface</p></figcaption></figure>

Now you can start again the simulation and you will see, that the Sensor is getting occupied (red):

<figure><img src="https://260262196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FpYxFg97YnJX96UzNNTSd%2Fuploads%2Fgit-blob-ce4007745ecccdf7b2a1b266c9a48ff8e1d665d3%2Ftutorial-simulatesensor.png?alt=media" alt=""><figcaption><p>Sensor in the Digital Twin during simulation</p></figcaption></figure>

{% hint style="warning" %}
Don't forget to save your model by selecting *File > Save*
{% endhint %}

### Summary and what's next

This is just a first quick starter. Please check the [Demo model](https://doc.realvirtual.io/basics/demo-model) and learn how the functions are realized. Also check the section [Physics ](https://doc.realvirtual.io/basics/physics)to learn more about the physics simulations, collision detection and kinematic movements. Based on that you should check the whole section [Components & Scripts](https://github.com/game4automation/doc/blob/doc/basics/broken-reference/README.md) to learn more about the details.

© 2025 realvirtual GmbH [https://realvirtual.io](https://realvirtual.io/) - All rights reserved. No part of this publication may be reproduced, distributed, or transmitted in any form or by any means, including printing, saving, photocopying, recording, or other electronic or mechanical methods, without the prior written permission of the publisher.
