3D World

HOW CAN I CREATE AN INTERACTIV­E DOOR IN UNREAL?

- Arnold White, Wales

Oscar Juárez replies

Creating archviz with Unreal Engine has advanced so much; it’s amazing how we can see our models coming to life, changing from daylight to dawn, turning on and off lights, adding and removing gadgets, and opening doors so we can enter bathrooms, living rooms, terraces etc. This is what we will explore here – creating an interactiv­e, opening door. Let’s get to it.

01 CREATE THE BLUEPRINT AND INTERACTIO­N RANGE

The first thing we need to do is create the blueprint class. Right-click in the explorer and select Blueprintc­lass, select the actor type and we will have our empty blueprint ready to tweak. Name it OPEN_DOOR – always remember to add an underscore between words, as in Unreal we can’t leave empty spaces. Open the blueprint and go to the viewport. In Add Component click and type ‘static mesh’. Select it and it will be placed, then click and drag over Defaultsce­neroot. Select the static mesh again, and now type again in Add Component and add another static mesh; it will be a child of the first one. Name the first static mesh ‘Frame Door’ and the second one ‘Door’.

Now in Add Component click and type ‘Box Collision’, then add it. Select the Frame Door static mesh and place the door frame that you should have already imported to Unreal. Select the Door static mesh and choose the door model you have imported in Unreal. Select the Box Collision and change its position and size so it can cover the door. This will be the area that will activate the ‘interactio­n’ when you are in range. Press Compile and then save.

02 RANGE SETUP

Now we have our blueprint with the 3D models, but it has no actions at all, so let’s go to the Event Graph tab. Delete the three nodes there (that’s what I usually do) and select the ‘box’ in the right menu. Scroll down and there will be the events options. Click ‘On component begin overlap’, then select the box again and click ‘On component end overlap’. Now right-click and type ‘enable input’ and place it, then right-click and type ‘disable input’. Connect ‘On component begin overlap’ to ‘enable input’ and connect ’On component end overlap’ to ‘disable input’. Finally from the ‘disable input’ click and drag in the player controller. A window will show, so type ‘get player controller’, and connect it to the player controller in ‘enable input’ too.

With this we have activated the area where our interactio­n will work, but we will add something else so we can see when we are in range. Right-click and type ‘printstrin­g’, place it and connect to ‘enable input’. Type ‘in range’ in the string option and set duration to 1 sec. Place another ‘print string’ and connect it to ‘disable input’. Type ‘not in range’ in the string part and set to 1 sec. Select all and press C. Name the group Enable / Disable. Compile, save and close.

Now in the viewport select the OPEN_DOOR blueprint and place it in the scene by click and drag. Set it in the right position and press play. Now you can see that each time you are close to the door, text will appear in the top left, and when you are away it will say ‘not in range’. This way we can see if this part is working before proceeding to the next step. Once we can see that it’s working, we can deactivate it.

03 SET ACTION KEY

We have the area where the interactio­n will be activated, but we still need what triggers the door to open and close. Open up our blueprint and go to the event graph. Right-click and press keyboard and scroll up so you can see the O key. Select it so the O is the key that will activate all. Now in Variables add a new one and name it ‘ISOPEN’, but leave it as it is for now because we will use it later. Next click and drag from the O option and type ‘branch’. Select it and click and drag the ISOPEN variable into the slate and connect to the ‘condition’ option within ‘branch’.

Next click and drag from ‘false’ within ‘branch’ and type ‘add timeline’. Add it and name it ROTATE DOOR – this is the one that will create the door rotation. Double-click so we can open it and add a ‘float track’ by pressing the F-looking

icon. Name it ‘rotate z’, change the length to 2, now right-click and select ‘add key to Curvefloat_0’. Set both values to 0, then add another one and set values to 2 and 90. Finally press the ‘zoom to fit vertical’ button, select each dot in the graph, right-click and select auto 1 in the key interpolat­ion. Compile and save.

04 FINAL SETTINGS

Now select the door component, then click and drag into the slate and set it as ‘get door’. Click and drag from it and type ‘relative’ and select Setrelativ­erotation. Once it has been added right-click in the coordinate­s and select ‘split struct pin’. This will separate X, Y and Z axis options, so as we need to rotate in the Z axis we will have to connect the rotate Z to the new rotation in Z and then connect the update within Rotate Door to the Setrelativ­erotation. Compile, save and test it.

So now the door opens but does not close, so we need to add two more components. In Components click and drag ISOPEN and set it as ‘Setisopen’ and check the isopen box. Connect the false to it and to the play within Rotate Door. Select the ‘Setisopen’ we created before and click Ctrl+w. This will make a copy and for this one uncheck the box. Connect it to the true within branch and to reverse within ‘Rotatedoor’. Compile, save and press play. Now we have a working interactiv­e door.

 ??  ??
 ??  ?? How can we add a functional opening and closing door to our scenes?
How can we add a functional opening and closing door to our scenes?

Newspapers in English

Newspapers from Australia