An example generated with the code from the Voxel Terrain Tutorial

Voxel Terrain in Unreal Engine 4 Part 4.5: Upgrading to 4.12

And we’re back with another part of the Voxel Terrain in UE4 tutorial! While the last few versions of Unreal Engine 4 have done wonders for code compatibility, this time around we have a small change to make to our project before we’ll be able to compile it with the new version of the engine. From this tutorial forward I will be continuing the series using Unreal Engine 4.12, up from 4.10. Make sure you apply this change before you try to upgrade to 4.12!

The Changes

This is actually one of the smallest changes I’ve ever had to make to upgrade a project to a new version of the engine. All we need to do is replace our custom-made ModulePath member with the newly implemented ModuleDirectory member, which acts as a direct replacement for our previous code. As a start, go find this chunk of code in your ProjectName.Build.cs file and remove it.

// The path to our game module; e.g. ProjectFolder/Source/ModuleName/
    private string ModulePath
    {
        get { return Path.GetDirectoryName(RulesCompiler.GetModuleFilename(this.GetType().Name)); }
    }

Next go ahead and replace all uses of the ModulePath member with the new ModuleDirectory member. This is actually really simple, we only had a single use of that member in our file. Find the ThirdPartyPath member and change it to the following:

// The path to our Third Party code assets; e.g. ProjectFolder/ThirdParty/
    private string ThirdPartyPath
    {
        get { return Path.GetFullPath(Path.Combine(ModuleDirectory, "../../ThirdParty/")); }
    }

With that change in place, you should now be able to compile your project. Just in case though, this is the entire file:

// Fill out your copyright notice in the Description page of Project Settings.
using System.IO; // Make sure you are using System.IO! Its not in here by default!
using UnrealBuildTool;

public class VoxelTerrain : ModuleRules
{
    // The path to our Third Party code assets; e.g. ProjectFolder/ThirdParty/
    private string ThirdPartyPath
    {
        get { return Path.GetFullPath(Path.Combine(ModuleDirectory, "../../ThirdParty/")); }
    }

    public VoxelTerrain(TargetInfo Target)
	{
		PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "ProceduralMeshComponent" });


        PrivateDependencyModuleNames.AddRange(new string[] {  });

        ////////////////////// Custom Voxel Terrain Stuff Starts Here //////////////////////////////////////
        // You will need to compile and add additional libraries if you want to use this on platforms not listed below!
        switch (Target.Platform)
        {
            // 64-bit Windows
            case UnrealTargetPlatform.Win64:
                PublicAdditionalLibraries.Add(Path.Combine(ThirdPartyPath, "accidental-noise-library", "build", "ANL", "x64", "ANL.lib"));
                break;

            // 32-bit Windows
            case UnrealTargetPlatform.Win32:
                PublicAdditionalLibraries.Add(Path.Combine(ThirdPartyPath, "accidental-noise-library", "build", "ANL", "x86", "ANL.lib"));
                break;

            // Mac
            case UnrealTargetPlatform.Mac:
                PublicAdditionalLibraries.Add(Path.Combine(ThirdPartyPath, "accidental-noise-library", "build", "ANL", "Universal", "libANL.a"));
                break;
            
            // Linux
            case UnrealTargetPlatform.Linux:
                PublicAdditionalLibraries.Add(Path.Combine(ThirdPartyPath, "accidental-noise-library", "build", "ANL", "x64", "libANL.a"));
                break;

            default:
                break;
        }

        // Include the headers for PolyVox and ANL so we can access them later.
        PublicIncludePaths.Add(Path.Combine(ThirdPartyPath, "polyvox", "include"));
        PublicIncludePaths.Add(Path.Combine(ThirdPartyPath, "accidental-noise-library"));
        ////////////////////// End Voxel Terrain Stuff //////////////////////////////////////////////////////
    }
}

I would also like to leave a link to the project’s GitHub page for anyone who isn’t already aware of it! I created this towards the beginning of the project, but I only ever mentioned it on Twitter, so I don’t think many people know about it. If you ever need to see how my entire project is set up, please check this out.

0 comments on “Voxel Terrain in Unreal Engine 4 Part 4.5: Upgrading to 4.12Add yours →

Leave a Reply