Rotating Meshes When Spawned

Hello everyone! I am working on a code to procedurally generate hallways as the player walks. I have that aspect of the code working. What I am having trouble with is that sometimes I need the spawned mesh to be rotated + or - 90 degrees on the Z Axis to connect with the hallway that spawned it. Pictures are provided below but the breakdown is this: I have 3 hallways (H1-H3) and 1 room (R1). if H1 spawns H2 or H3, they are fine and can be left alone. But if H1 spawns R1 this room has to be rotated 90 degrees on the Z Axis. Here is the code and how each hallway is set up:


So each room uses a collision box to spawn the next room when the player walks through it. The next room to spawn shows up with its Default Scene Root overlapping the LocSphere asset at the exit of the room.

This is the BP that spawns new rooms. It chooses one of the other rooms randomly via the Selection node and spawns it on the LocSphere. What I’m having trouble with is how to target a specific BP to rotate as needed. My idea was to use the following function, and hook it to a Branch at the end of the above BP to tell the engine “hey if R1 is spawned off of an H1, it needs to be rotated 90 degrees”:

When I put that plan into action, however, my H1 deleted itself from the world and R1 remained unrotated. Any ideas for what to do here?

1 Like

Select and Random Integer in Range are Pure nodes, which means they’re re-executed every time you access their output. I would suggest

promoting the return value

(You can promote it by right clicking on the Return Value on the select node and choosing Promote to Variable)

of the select node to a variable after the Do Once

You can rotate just R1 by doing the following :

  1. The Return Value of the Spawn Actor node gives you a reference to the actual actor that was spawned in the level. Drag of of the Return Value and Cast it to R1.
  2. If the Cast was successful, drag of from the Cast node’s As R1 output and search for Set Actor Rotation and set it to the rotation you want.

H1 didn’t get deleted, in the Rotate Room 1 function you’re setting it’s location back to world origin (X 0.0,Y 0.0,Z 0.0).
image

If you only want to rotate an actor you can use Set Actor Rotation instead of Set Actor Transform.

1 Like