Download

How to exclude files from being compiled ?

Today I discovered something extremely important about UE4, it has 2 distinct build configurations, with and without the editor. This in turn creates a lot of issues when extending an editor feature like say an animation graph node.

I made something like this :


class UAnimGraphNode_Custom : public UAnimGraphNode_Base

and I discovered that I need to add dependencies based on whether I am building with the editor or not :



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

        if ( UEBuildConfiguration.bBuildEditor )
        {
            PublicDependencyModuleNames.AddRange(new string] { "AnimGraph", "BlueprintGraph", "GraphEditor" });
        }
}


Everyone that modifies any feature of the editor needs to do this. I’m shocked there’s nothing in the wiki or the documentation about this. This along with excluding the relevant bits with “#if WITH_EDITOR”
However, the .cpp file, where I defined UAnimGraphNode_Custom is still getting compiled and I get errors that some other classes are missing (due to it being a development or ios builds where the editor is excluded). It also looks like the build tool is ignoring the “excluded from build” parameter from Visual Studio AND Xcode, so how do I exclude this file only on the non editor builds ?

So no one knows how to do this for C++ projects ?

Have you tried AnswerHub mate ?

Well I am complete noob but I remember a “Transient” command somewhere making some features completely independent making them compile-and-forget in the editor. Maybe something similar solves this ?

Are you putting your editor code directly into your game module, rather than making another module for your editor specific code as outlined here?

But I don’t want to create a module, the extended class should be part of the project. So an Unreal Engine Developer can’t tell me how to exclude .cpp-s from a project ? I was expecting this to be as easy as it is in Visual Studio, is it really that much to ask ?

I believe you’re thinking of plugins here. Yes, plugins are separate from game projects and should not depend on said projects.

But modules are still part of a project and can be specialized to only be loaded for editor, server, client, etc., which is exactly what you need here. If you’re trying to conditionally exclude code from editor builds without making an editor module, then you are shooting yourself in the foot, to put it bluntly. At least making new modules is fairly trivial in UE4 compared to the DLL hell it traditionally is.

E: Since your original post refers to animation nodes, I can give a general lead for that specific case: The actual FAnimNode needs to remain in the game module, and the editor-specific UAnimGraphNode would be moved to the editor module. Be warned that this particular setup has caused issues in the past.

-Camille