Importing a Blender map

Exporting a Map from Blender into UE4 The purpose of this page is to provide the required steps to import a map from Blender into UE4. It is possible to use Blender as a rudimentary UE4 map authori...

Updated over 4 years ago

Exporting a Map from Blender into UE4

The purpose of this page is to provide the required steps to import a map from Blender into UE4.

It is possible to use Blender as a rudimentary UE4 map authoring tool to create basic maps which can then be expanded inside the UE4 Editor.

Why use Blender to make UE4 maps?

Some users will be more efficient using Blender to create basic map meshes than using the tools within UE4.

Blender is able to handle the early stages of "roughing out" a UE4 map.

Authoring the early "roughing out" content of a map within Blender opens up the possibility to use Blender as part of the workflow. This is attractive to some members of the UE4 community with skills and experience in Blender.

Using Blender for this work will not detract from the overall quality of the final map produced.

File:BlenderMapExample.png

Concepts

The most basic scenario is to create and export a rectangular prism. To achieve this objective two objects are required in Blender:

  • A rectangular prism to display in UE4 (visual); and
  • A rectangular prism for collision calculations in UE4 (physics).

If only a single general purpose mesh is provided, then within UE4 the player will “fall through” this mesh (if they are standing on it and if gravity is applicable) or walk through this mesh it is being used as a wall.

UE4 relies on the specific structure of the names of the exported meshes to understand the purpose of each mesh.

Naming Requirements

UE4 will read the name of each mesh when importing into UE4 to determine if a mesh is:

  • a display mesh; or
  • a collision mesh.

To create a rectangular prism for the UE4 player character to stand on requires:

  • a visual mesh (the rectangular prism which is displayed in UE4) can be named almost anything; and
  • the associated collision mesh (which is usually the exact same size and dimensions of the display mesh) will require a special name.

There are four special collision mesh names. Each type depends on the shape of the collision mesh to be generated by UE4.

  • Box – UBX_[RenderMeshName]_##
  • Capsule – UCP_[RenderMeshName]_##
  • Sphere - USP_[RenderMeshName]_##
  • Convex Object – UCX_[RenderMeshName]_##

UE4 will interpret the vertices in the collision mesh and then create a physics object corresponding. Therefore the collision mesh created in Blender is more akin to an instruction to UE4 than hard geometry physically depicting the shape of the object.

If a collision mesh is created within Blender as a rectangular prism but the name of that mesh includes the sphere prefix ("USP_") then UE4 will create a sphere collision object rather than the rectangular prism that was authored. Pay close attention to the names given to meshes in Blender.

The official guide to the collision meshes and their usage is found at:

Workflow

The required workflow includes:

  1. create visual meshes in Blender including basic texture information;
  2. create collision meshes in Blender;
  3. select both visual and collision meshes in Blender and export to an FBX file;
  4. import the FBX file into UE4 as a static mesh;
  5. place the map into UE4; and
  6. update materials on the map as needed.

Textures/Materials from Blender to UE4

The materials used in Blender can be influence (but not completely control) the materials used by UE4. The connection is based on the material name. In summary the material process is:

  • set up UV coordinates on the display meshes (noting the collision mesh is never rendered and so never needs UV coordinates);
  • apply a material in Blender (empty is ok); and
  • in UE4, create a material with the same name and it should be applied to all the mesh elements that had that specific material applied in Blender.

Automating the creation of collision meshes

For any map that is more than a trivial placement of boxes it is a tedious process creating each related collision mesh after the visual meshes are created. The following python script which can be run in Blender will automate this process:

This script will:

  • take any selected meshes;
  • create a duplicate of them in layer 2 (collections in versions of Blender 2.80 or higher);
  • name these newly created meshes according to the format "UXC_[mesh_name]_[number]" (this will allow UE4 to interpret these meshes as collision meshes).

For completeness the text of the script captured below, copy this into a Blender text window and run:

#14 April 2020
#Updated the Layer 2 references to a new Named Collection

#1 December 2018
#Added functionality to toggle auto-unwrap on or off

#26 December 2017
#Dingo_aus 
#Script adds geometry that Unreal Engine interprets to be the collision volumes. Collision data will be added to layer 2 in Blender
#script requires objects to be selected for collision to be added

#0) remove the full stop from previsouly duplicated names
#0.5) Smart Project Unwrap each item (calculate UVs)
#1) Duplicates all selected objects then
#2) runs through a loop and finds the duplicated items with ".001, .002, .003 etc" and renames these 
#   objects to be collision objects. Will also put the collision volumes on Layer 2.

#GLOBAL VARIABLES
#set the variable below to 1 if you want the script to automatically unwrap the UVs of each selected visible mesh.
SHOULD_AUTO_UNWRAP = 0

import bpy
print("Start---------------- ")
#0)

for obj in bpy.context.selected_objects:
    obj.name = obj.name.replace(".","_")
print("---Any fullstops in names successfully replaced with underscores... continuing")

#0.5) - Smart unwrap each object's UVs if GLOBAL variation set to unwrap

if SHOULD_AUTO_UNWRAP == 1:
    bpy.ops.object.mode_set(mode = 'OBJECT')
    unwrapcount = 0
    for obj in bpy.data.objects:
        #bpy.ops.object.select_all(action= 'DESELECT')
        #if obj.layers[0] == True:
        #    bpy.context.scene.objects.active = obj
        #    obj.select = True
        #else:
        #    continue
    #Just to be sure that is everything deselected
        bpy.ops.object.mode_set(mode = 'EDIT')
        bpy.ops.mesh.select_all(action = 'DESELECT')
        bpy.ops.object.mode_set(mode = 'OBJECT')
        print("---unwrapping: " + obj.name)
        bpy.ops.uv.smart_project()
        unwrapcount = unwrapcount + 1
    print("---Total objects unwrapped:" + str(unwrapcount))
    print("---All objects have been unwrapped")
elif SHOULD_AUTO_UNWRAP == 0:
    print("---No Objects Unwrapped, original set UV Coords used---")

#1)
#Duplicate selected objects...then rename to be the collision
bpy.ops.object.duplicate()

print("---All objects duplicated")

#3)
#For versons of Blender 2.80 and greater
#Create the Collection that we are after
newCol = bpy.data.collections.new('collision_data')
bpy.context.scene.collection.children.link(newCol)

#rename objects
n = 1
for obj in bpy.context.selected_objects:
    n = n +1
    oldname = obj.name
    temp_str = oldname[-4:]
    temp_str2 = "."
    #print(temp_str)
    if temp_str[:1] == temp_str2:
        print("CANDIDATE TO CONVERT TO PHYSICS VOLUME HAS BEEN FOUND: " + oldname)
        #add prefix
        obj.name = "UCX_" + obj.name 
        #remove last four characters
        obj.name = obj.name[:-4]
        #add postfix
        postfix_str = str(n)
        obj.name = obj.name + "_" + postfix_str.rjust(2, '0')
        #*************
        #For versions of Blender earlier than 2.80
        #add to separate layer so export can exclude UCX objects and painted in Substance Painter etc
        ##move to layer 2
        ##obj.layers=(False, True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False)
        ##print("Collision volumes assigned to layer 2")
        #*************
        #For versions of Blender 2.80 or higher
        newCol.objects.link(obj)        
        print(obj.name)
print("Success!")