-
Notifications
You must be signed in to change notification settings - Fork 14
Using Blueprint Properties
This tutorial assumes you have completed the Using Actor Events.
In this tutorial we will learn how use Blueprint properties to customize our actors in the editor and reading and modifying those properties in Kotlin.
We will add a Speed and Yaw variables to our CubeTutorialBlueprint, to be able to configure different speeds for each cube in the editor, and check how the variable Yaw will get updated by our code.
Open the CubeTutorialBlueprint you created in the previous tutorial. Add two variables named "Speed" and "Yaw" using the + button in the Variable section. Make them public and set their Variable Type as float.
Compile and save, and get back to the code.
To be able to read and write those variables we will create an external class definition that will represent our Blueprint.
In the future, this process could be automated so you don't have to write this class manually.
external class CubeTutorialActor: Actor {
var Yaw:Float
var Speed:Float
}
As you can see, it is just a class with the variables we just added and their type.
What we are going to do now, is to use the Speed variable instead of the constant we used in the previous tutorial. Also, instead of using a variable defined in our class to store the yaw value, we will use the one provided by the Blueprint.
Our code will look like this now.
import ue.*
external class CubeTutorialActor: Actor {
var Yaw:Float
var Speed:Float
}
class CubeTutorial: KotlinObject() {
override fun Tick(deltaTime:Float) {
val actor = GetOwner<CubeTutorialActor>()
actor.Yaw += actor.Speed * deltaTime
actor.SetActorRotation(Rotator(Yaw = actor.Yaw), false)
}
override fun BeginOverlap(other: Actor):String {
println("Collided with $other!")
return ""
}
}
Now compile the code, by pressing the "play" button, and get back to the Unreal editor.
Now select the instances of the CubeTutorialBlueprint you may have on your level, and change their Speed variable to different values.
Enter into play mode, and you should be able to see the cubes rotating at different speeds, and also the current value of the Yaw variable will be reflected in the editor. Also if you change the value of the Speed variable while the game is running, you will see the cube changing its rotation speed accordingly.
Is this some kind of magic?
Definitely.
Next: Hot Reload