Create an Interface Using Blueprints in Unreal Engine 5
Creating an interface can be fun and simple in UE5 and definitely be valuable tool while programming game logic
Software Version: Unreal Engine 5.4.4
Interfaces are a great way to listen for events happening in the game world without having to cast to an actor or be referenced directly. In this brief example I make very small interface that platforms inherent and move to the position when called.
Start by creating a Blueprint interface. I created one and gave it a generic name, I_Cycles
.
Next I added an empty function to the interface called MovePlatforms
. Each platform will then listen for this event.
Then I created a Blueprint Actor that simply has a cube component. You have to add the interface to the Blueprint under Class Settings so it listen for events. When the MovePlatform
function is called, the mesh component slides to it's actor's root position of FVector(0.0, 0.0, 0.0)
. I also added a timeline to smoothly transition location during the lerp
phase.
After that, I made a simple Lever
Blueprint with a Box Collision
that OnComponentBeginOverlap
will call the MovePlatform
function for each actor inside its Platforms
array variable.
When we're all done making the Blueprints we then put them into action. I put the lever on top of ramp and then dragged in 4 BP_Moving_Platforms
, adjusted their mesh component accordingly, and then added the platforms to the lever's Platforms
array.
When the trigger is activated the platforms will come together and to form a bridge for the player. A small piece of gold is waiting for the player at the end.
Quick, simple, and super helpful.
Harrison McGuire