[UE4] Editor raytracing for roof detection

Hi guys, I made a blueprint which I found useful to execute some automatic procedures with objects that are placed under a roof.

This can be useful during an open world production where you have tons of objects and you don’t want to rely on manual control on each of them.

In a production situation, you want your walls and roofs to be custom type blueprints to recognize them without the use of component tags, that we are using in this tutorial.

 

This is the setup of my example scene, some walls and roofs with component tags “Roof” and “Walls” assigned in the detail panel, and some basic shapes with None component tag.

 

01.PNG

 

02.PNG

 

Follows the setup of the blueprint and the explanation:03.PNG

The blueprint gets all the actors of type “static mesh actor” from the scene, loop them checking the component tag of each and raycast from the right ones to check the collisions.

Let’s analyze it deeper.

 

04.PNG

It starts clearing the two temp arrays we use during the process, so every time we hit the custom event from the editor it will start from scratch. Then it gets the static mesh actors from the scene and copies them in a temp array.

 

 

05.PNG

Iterating the temp array we check each item component tag, and we create another temp array to get only the meshes with tags different from “Roof” and “Walls”.

 

 

06.PNG

Once the first loop is finished and we have a temp array (“None tagged meshes”) which contains just the meshes we want to use for the raytracing, we can go ahead and start doing that. The Z-Search value float is used to control the length of the ray, once the raytracing is over we check the hit component tag and, in this case, assign the right material to the object.

The next image shows the different materials applied to different objects based on what their raycast hit.07.PNG

This process can be easily extended to other features, like checking also walls with multiple raycast.

Another solution can be a sphere collision which detect custom collisions defined for roofs and walls.

 

This was a basic tool but I hope it can be useful to someone.

 

Bye!

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s