Skip to content

Using Actor Events

hiperbou edited this page Feb 28, 2021 · 7 revisions

This tutorial assumes you have completed the Hello World Tutorial.

In this tutorial we will learn how to call Kotlin code that will be executed on the Tick and ActorBeginOverlap events.

First create a new Actor Blueprint by right clicking on the content browser and selecting Blueprint Class and selecting **Actor ** as base class. The new Blueprint is created so let's name it something like "CubeTutorialBlueprint". Open the newly created Blueprint by double clicking it.

Then let's add a Static Mesh and the KotlinComponent to our Blueprint. Click on the Add Component button and select "Cube", then drag and drop the "Cube" component over the "DefaultSceneRoot" to override it. Click on the Add Component and search for "kotlin" and add the Kotlin component.

Now, select the "Kotlin" component and in the details panel, look for Kotlin Class and set it to "CubeTutorial". That will be our Kotlin class that will contain our code.

To make things even more interesting, add a Box Collision component by clicking on Add Component and select Box Collision, and now scale it to 2,5 in every axis.

The result should look similar to this.

We will use the Blueprint events in order to call our Kotlin class functions. Go to the Event Graph tab and select the "Kotlin" component. Then rigth click in an empty space on the Event Graph and select Call Function on Kotlin/Kotlin/Begin Overlap Repeat the process with Call Function on Kotlin/Kotlin/On Tick

Tidy up and connect everything like this:

Clone this wiki locally