top of page

Direction Vector Mapping


In the above example, using Switch on Enum requires setting lots of Vector nodes that take up space in the graph. This post shows a way to compact the setting of direction vectors using fewer nodes.

It is based on an enumeration asset called Direction.


Since direction vectors are a matrix like this:

Direction

X

Y

Z

Up

0

0

1

Down

0

0

-1

Right

1

0

0

Left

-1

0

0

Forward

0

1

0

Reverse

0

-1

0

In Unreal you can create an Enumeration, with Up, Down, Right, Left, Forward, Reverse.

This lets you create, as in the top example, a Switch on Enum (Direction) node in Blueprint graphs.


But it's annoying to set some stack of vectors and write them up, and it takes space.


So, instead, take the Enum variable and change its type to Map in the Details panel. Then add Vector as the pair type.



Before compiling the blueprint, add 'Map Elements' entries (as with an array). For this setup, it needs 6 elements. Make sure to add the default enum value last; you can't add additional entries while the first map has the default value.

Effectively, this creates a mini datatable we can lookup using the Find node:


In the picture above, there is a Branch node for the success of the Find, but if the enum can only supply a Direction that is in the mapping, it'd never fail (unless there was a typo in either during setup).


Functionally, this is equivalent to doing the following, but clearly it takes less space in the graph:

With a mapping, you can also alter the map values (though with Direction usage that'd be unusual).


After all that, make the Extrude Direction (Direction enum) public so it can be set in the editor.






Comentários


Featured Posts
Recent Posts
Search By Tags
Follow Us
  • Facebook Basic Square
  • Twitter Basic Square
  • Google+ Basic Square
bottom of page