Separating Editor and Game code

Making two separate modules is the officially supported and recommended way to do this, particularly once you’re getting to requiring code from editor-only libraries. You can find more information on setting that up here: What is the proper method for extending the Editor Engine? - C++ - Epic Developer Community Forums

As an aside, the Classes folder is a semi-legacy thing that we don’t recommend using for new code. It exists because UHT didn’t used to parse the Public or Private folders when looking for headers, however that has long since been fixed, and these days we recommend putting all your code in either Public or Private (depending on whether it needs to be accessible from the outside). This promotes better encapsulation of your module, and also avoids potentially large rebuilds, as the headers in the Classes folder get lumped into a single massive include file which can cause all of your code to rebuild when changing a header - the other folders don’t have this issue as they allow you to go with an “include what you use” strategy instead.

Hello,

I have a question about separating Editor and Game code. I have this structure of my project:
foo
\ Classes (all the UObject derived classes are here)
\ Private
\ Public

In my .build.cs file, I have UEBuildConfiguration.bBuildEditor check and add Editor modules only if it is true. This works well, but when UHT runs, it tries to parse all UObject derivatives in \ Classes and obviously fails on those that are Editor dependent (basically cannot find superclass when processing). I tried adding WITH_EDITOR checks to those header files, but it seems UHT completely ignores that setting, as in it is always set, even for pure Game builds.

Is there anything I can do? Other than splitting into two separate modules… Thanks.