In this prolonged tutorial we will talk about using the Apparatus plugin inside Unreal Engine. You will create your first detail and implement the game mechanics in a special Blueprint class. We will demonstrate the most important features on the example of a simple two-dimensional platformer.
Just before going any further, make sure you have a basic understanding of ECS. Check our brief introduction to the ECS concepts.
D_Moveable
,D_Moving
,D_OnFloor
,D_Fallable
.D_Moveable
class with a default value of 100.0
.ETouch Swipe Direction
named Direction
to the D_Moving
class.Box Collision Object Reference
named ‘Bottom’ to the D_Fallable
class.(0.25, 0.25, 0.25)
with parentheses and paste into the scale vector with right mouse button click; if all’s right you’ll get corresponding values in the vector). Add a ‘Spring Arm’ component to the ‘DefaultSceneRoot’ and the Camera to the arm (make sure that transform vectors are set to their default values); then rotate the arm over the Z-axis by 180° and after that rotate it over the Y-axis by -30°.+
button and selecting the detail class. Add exactly two details like on the following shot:D Moving Object Reference
. I.e. after the detail was added you can ‘promote it to variable’ and call functions from it or access variables. In our case we will change the Direction variable to corresponding value. Don’t forget to pin all of the Reuse Disabled checkboxes (We will talk later why you should do so). The whole scheme now should look like so:Delta Seconds
value to a global GlobalDelta
variable mainly for convenience purposes. Now we need to iterate over all of the subjects and for each of them, check if it complies with our special case. So, for that drag the next node - ‘Sequence’, and from its first output drag the filament link and find the ‘Mechanic’ node.D_Moveable
and D_Moving
. Promote the Moving
detail to a TempMoving
variable - or you’ll get yourself too much “noodles”. From the ‘Subjective’ output pin drag a ‘Get Actor’ pure function. That is also provided by Apparatus and returns the actor that is currently being processed. From this function’s output drag a ‘AddActorLocalOffset’ node. From the D_Moving
pin drag the ‘Direction’ variable and make ‘Select’ block to easily choose the corresponding vector depending on the direction currently active in the detail. ‘Left and ‘Right’ cases are split into components and fill the Y-component of the left-side case with the ‘Speed’ variable obtained from the ‘Moveable’ detail and multiplicated by the ‘GlobalDelta’ variable. For the right-side case use the same value just with an opposite sign. Below your ‘AddActorLocalOffset’ node place the deactivation of the ‘TempMoving’ detail be setting its state ‘Enabled’ to false. After all the above actions you should have something like that:What’s actually going on here? As you may remember, we defined how we determine our keyboard input at some previous step (by adding a D_Moving
details). Here we just move each actor with the pointed details (D_Moving
& D_Moveable
, only the pawn in the scene have this set) over their local Y-axis (for the camera view, it’s actually moving to the left if Y-axis is > 0 and moving to the right otherwise). So, depending on the direction we obtained from the ‘Moving’ detail we move an actor across the scene. After doing so, we disable the D_Moving
detail, so it won’t be moving to the side anymore. Good. But what will happen when the player presses a D or a A key a second time? Do you remember the checkbox we pinned? The ‘Reuse Disabled’ in fact means that if the ‘Subjective’ has a disabled detail then the function will enable it and return as its output instead of creating a new one. So now you can run the game and check if it works. Use A & D keys to move the box around.(X=0.000000,Y=0.000000,Z=-13.5)
(X=0.400000,Y=0.400000,Z=0.025000)
. After that in the ‘Collision’ section select the ‘OverlappAll’ collision preset. In the ‘BP_MainPawn’ editor the picture should look like so:Anyways, that’s it for this tutorial and the result should look similar to:
The project on github, take a look on the ApparatusLearn#1 branch
Apparatus is a really capable plugin, more than just a plugin - it’s a full-fledged data-oriented framework. It provides you with a bunch of new programming principles and techniques. Those are usually called data-oriented since we usually thinking Detail-wise. You can use the framework in your own production pipeline and extend its capabilities even further by declaring and implementing your own C++ classes, adhering to the necessary Apparatus interfaces.
The vast functionality of the framework can’t be easily demonstrated in a tiny tutorial like this. The main purpose of this article is exactly to introduce the beginners to the ECS approach in general and Apparatus in particular. Check our the following links also and don’t hesitate to ask any of your questions online on our TurboTalk forums and/or Discord server. We are eager to help and your are more then welcome to ask all sorts of questions!