lightbulb-onTutorial 4: How to create custom events that can be triggered upon completion of a task?

Making a Ligh bulb

In this example, we want to simulate screwing in a light bulb and turning it on with a button.

The exact sequence should work as follows:

You should grab the light bulb, place it into the designated socket, and screw it in clockwise by hand. Once this is done, push a button, and the lamp starts to glow.

First, we want to import the provided 3D model of a light bulb and its corresponding socket.

To do this, download the 3D model using the link below.

https://www.dropbox.com/scl/fi/gys18hmhbyxp4tx1xwyct/LightBulb.rar?rlkey=aihv0r6y8hqknbc0trivgqjam&dl=0arrow-up-right

Then, import it into the Content Browser using the Datasmith interface. During the import process create a folder with the name "Import". Use this folder to save the bulp and socket mesh.

During the import process create a folder with the name "Import". Use this folder to save the bulp and socket mesh.

Place the two imported objects in the scene as shown.

Now, in the first step, we want to convert the light bulb using the Turnable Transformer.

  1. Select the light bulb in the scene.

  2. Then, in the Transformer tab, choose the Turnable Transformer.

  3. Assign the Slot Name: "Bulb"

  4. Click the button labeled Assembly.

  5. Under Head, leave it empty this time, since the light bulb should be screwed in by hand, not with a tool.

  6. Finally, click Spawn to complete the transformation.

The result should look as follows: In the Outliner, you will see that the Part and the Holo (Slot) components are positioned on top of each other.

Select the Part component and move it to the left.

The final result should look like this:

  • The Holo (Slot) remains in the correct socket position.

  • The Part (light bulb) is slightly offset, ready to be picked up and screwed in manually.

Before you can test this interaction in VR, you need to activate the turnable using the Tasklist Editor.

To do this, follow these steps:

  1. Create a new tasklist and give it a name.

  2. In the new list, create a section that contains a task.

  3. Assign the Turnable Actor to the task.

  4. It should look like this:

In the next step, we’ll add a button to the scene to simulate the lamp’s switch.

To do this, go to the ToolSpawner tab and select Button.

Place the button below the socket.

To activate the button, create a new section with a task in the Tasklist Editor.

Assign the button to this task.

As you may have noticed in previous tutorials, you can add an event to any task.

In its simplest form, this event is configured to make an actor in the scene—one that was set to "Actor Hidden in Game"visible either at the start or upon completion of the task. Dont forget to asign that actor to the event!

When you click on the dropdown menu in the middle, you’ll see options such as Show, Hide, and Notify.

For this exercise, please select Notify.

In the next steps, we will create a Blueprint that can communicate with this event. To do this, create a new Blueprint named BP_HandleCommunication under VRAssembling/Blueprints/Special, or in a folder of your choice. Open the created BP by double clicking on it.

To enable this blueprint to communicate with the Tasklist Editor, we first need to add an interface class.

Do this by clicking on Class Settings (top row), then go to the Details panel and click on the Add dropdown under Implemented Interfaces.

The interface we want to add is called BI_AssemblyEvent.

Type this name into the search field and click on it to add it.

You have now successfully added the interface.

Next, click Compile and Save.

Now switch to the Event Graph view and focus on the left side.

There, under "Interfaces", you will see the Custom Assembly Event.

Double-click on it to bring the event into the Event Graph.

In the next step, drag off from the Info pin and create a "Switch on String" node.

Then connect the execution pin from the event to the input of the switch node.

Next, click on the Switch on String node and turn your attention to the Details panel.

Click the plus icon next to "Pin Names", and add a new pin with the name "LightOn".

Click save!

Now drag the newly created Blueprint into the viewport.

Make sure it is selected in the scene.

Open the Tasklist Editor and navigate to the Button Task.

Set the first dropdown to "On Finished" and the second dropdown to "Notify".

In the text field, enter the pin name "LightOn" and assign the blueprint actor we created earlier.

When the user now presses the button and the task is completed, the BP_HandleCommunication blueprint will be triggered, and the pin named "LightOn" will be executed.

Since this pin doesn't yet have any functionality connected to it, we will set that up in the next step. Open the blueprint.

First, we want to create a reference to the material of our light bulb.

To do this, create a variable of the type BP_Part_Turnable. Make sure to set the variable type as an Object Reference.

Set the variable to public by clicking on the eye icon next to it.

Click Compile and Save.

Then go to the viewport, select the BP_HandleCommunication blueprint in the scene, and turn your attention to the Details panel.

Under Default, you’ll find our variable "Ref Bulb". Use the eyedropper tool to select the Part component of the light bulb.

It should look like this.

Now go back into the Blueprint and create the required functionality.

Drag a Get reference of the variable "Ref Bulb" into the Event Graph.

From there, create a "Set Material (Static Mesh)" node.

As the material, select M_Emissive.

To summarize everything:

We grab the light bulb and screw it into the socket. After that, we press the button.

When the button is pressed, the task is considered complete, and the event is triggered by executing the pin named "LightOn".

In this function, the material of the light bulb is changed to make it appear as if it's glowing.

Congratulations, you have now completed another tutorial.

Last updated