Skip to content

Hello World

hiperbou edited this page Feb 28, 2021 · 5 revisions

Hello World Tutorial

This tutorial assumes you have a basic knowledge of the Unreal Engine editor, followed the Installation instructions and successfully run some of the examples.

Create a new level (File/New Level) and add an Empty Actor to the level.

Now select the new actor and we will attach the KotlinComponent to it.

Press the Add Component button and search for "kotlin". The component should appear, and it will be added after you click on it.

Now under the section "Kotlin" change the "Kotlin Class" property to "HelloTutorial"

What it's going to happen now, it's that the KotlinComponent will look for a Kotlin class named HelloTutorial and execute its code. But first, we need to create the class. Make sure you have configured IntelliJ IDEA following this instructions.

Create a new Kotlin class on the src folder using right click/New/Kotlin Class/File

You will be asked for a name for the class, so enter "HelloTutorial". Then copy and paste the following code:

class HelloTutorial: KotlinObject() {
    init {
        println("Hello World!")
    }
}

Our new class HelloTutorial extends from KotlinObject because we need this to be able to interact with the KotlinComponent we added to the actor. The init block will be executed on the KotlinComponent's event Begin Play, so that means that we should see a message on the Output Log and the Javascript Console, when the level starts.

Let's build the code by pressing the "Play" button, that will run the Build configuration.

Get back to the Unreal editor, and make sure to enable the Javascript Console using Window/Developer Tools/Javascript Console

Now press Play on the editor, and check the Javascript Console.

Congratulations.

Next: Using Actor Events

Clone this wiki locally