SPEAKER: Hey, everyone, and welcome back to another Unreal
Tips and Tricks series.
In today's episode, we will show you
how to play a car door open and close sequence
in a few simple steps using the Sequencer
tool and a hot key input to trigger the animation
via a Blueprint system.
Let's get started and check the structure of our car.
I imported the model using Datasmith.
We can see that Datasmith did a good job importing
the components respecting the child-parent linking.
Let's take a closer look at the Door_Passenger.
We can see that the components are a child of Door_Passenger,
that meaning that all of the door parts
are attached to that actor.
Now if I press G on my keyboard to show the actors
and select that specific actor called Door_Passenger,
I can start rotating it and see that all of the door components
rotate also, which is exactly what we want for our animation.
Our next step is to record that rotation animation.
And for this case, we'll use the Sequencer tool.
Let's go to our Cinematics button
on the toolbar and let's click on Add Level Sequence.
Let's name this Door_Open.
Press Enter, and this will open a new Sequencer tab for you.
Let's make sure that we set the Loop to Don't Loop
and that the Pause at End is enabled.
Now with that created, let's select our actor
in the viewport.
So let me enable the actors by pressing G on the keyboard.
Let's grab the actor, so Door_Passenger in my case.
And let's go to our Sequencer tab, right click, Actor
to Sequencer, and add Door_Passenger.
So what we want to do here is track the transform properties.
So I'm going to go in on the plus (+) sign here track,
and let's enable the transforms.
Let's expand the properties, and we
can see here that we have location, rotation, and scale.
So we're going to be looking at the rotation here.
We can already set a keyframe for the default states
at frame zero.
So I'm going to go ahead and press plus (+) here.
Now, I like to use the auto key framer,
so if you press on this button here,
this is going to enable the key framer.
And let's jump to frame 19.
And let's make sure that we have the angle snap turned on,
so I'm going to enable it again and change
my degrees to 5 degrees to have a bit more precision.
Let's press E on the keyboard, and let's start
capturing that property.
So I'm going to make my door open 40 degrees.
Now, as soon as I let go of my mouse,
this creates a keyframe for me.
So if I scrub through the animation,
we can see that the door is opening and closing correctly.
So let's make sure that we set the default 150 end
range to now 90.
Now that the sequence is done, let's jump into the Blueprints
and trigger the animation with a hot key.
So let's jump into our content browser and right click.
And let's create a Blueprint class.
And this is going to be an actor.
So I'm going to name mine BP_DoorAnimation.
So once that is created, let's go into the Event graph.
And for the sake of the tutorial here, I'm
going to be using the Event BeginPlay.
So I'm going to delete these two nodes.
And the first thing that we want to do
is make sure that the input is enabled.
So I'm going to go in the Event BeginPlay
on the node and type in Enable Input.
And the second thing that we want to do
is get the player controller.
And this is going to ensure that the input is correctly
detected.
Now, the second thing that we want to do
is get all active class and specify
that we want to get the level sequence class.
So I'm going to drag an node and type
in get all actors of class.
And this is the one I'm going to be using.
And in the actors class I'm going
to be specifying that we are going to be using the level
sequence actor.
So out of that away, we want to get a copy.
So I'm going to type in get copy.
And from that copy, we're going to promote a variable.
So I'm going to right click right on that blue node
and promote to variable.
And this has created a new variable for me.
So I'm going to just name it something a bit more adequate,
like Door Anim.
And we can see that the variable type
is corresponding to the level sequence, which
is what we want.
So I'm going to drag that node and make sure
that it's correctly set up.
So the second thing that we want to do here
is enable a key input.
So I'm going to be using my keyboard.
But you can use a controller if you want.
So I'm going to right click here,
and I'm going to be using on O key on my keyboard.
So I'm going to type in O keyboard.
And that's going to bring me that input.
And I want to be using the same input for opening and closing.
So what I'm going to do here is use a flip-flop node.
And basically what we're going to do here
is say that A is going to play the animation,
and B is going to reverse the animation.
So before we do that, let's grab our door animation variable
that we created, and let's get the Door Anim variable.
And we're simply going to type in here, Play Sequence.
And so this guy here, we can get the Play Sequence.
And I'm going to drag another node,
but this time, I'm going to do Play Reverse Sequence.
And all I have to do here is plug A to the play sequence
and B to the play reverse.
Now once that is done, let's compile and save.
So once in our scene, let's make sure to drag
the Blueprints actor into the viewport,
and let's go into our play mode and test it.
So I'm here in the scene, and I'm
going to press on the O keyboard input.
And we can see that it's correctly opening the door.
And if I press the same key again,
it's going to reverse that animation.
I hope you enjoyed this video and hope
to see you very soon in the next Unreal Tips and Tricks series.