I recently started encountering errors with every new C++ class I try to add to my project. As you can see from the screenshot below, the compiler is complaining about syntax errors in an unrelated file (PlayerState.h) which is read-only and has not been modified from the engine source in any way.
This error pops up as soon as I try to add any empty class to my project. The class name, path, and base class do not matter. The issue goes away as if I delete the newly added header/.cpp files and recompile.
Any ideas? C++ development is effectively shut down until I fix this. I’m using VS2022 and running UE 5.03 but the bug is persisting after upgrading to 5.2 as well.
my hunch is that your includes are not robust enough.
and it compiles ok because you use the unity mode, and the order just works well enough. but as soon as you add a class that order breaks and your stuff breaks.
Despite the compiler errors, I am certain playerstate.h is not the source of the problem for a couple of reasons:
as I mentioned, this is an unmodified engine source file that is read-only. It’s complaining about the syntax of the ClientInitialize function, which is fine.
the compile error shows up immediately when adding any new empty C++ class, completely unrelated to playerstate, no headers, references, etc. There were never any problems adding new classes until recently.
the same type of error has been reported before by another user with a different class other than playerstate: Creating new C++ class leads to compile error. As this user mentions, I suspect the issue is the init.gen.cpp files are not being properly generated, I just don’t understand why or what could have caused things to break.
Interestingly, I was able to recreate the error in a fresh UE 5.2 project that was empty except for the source files I copied over.
how are you adding the C++ classes? are you using the Editor to add them, or are you creating raw files in your IDE?
are you running VS2022 community, or Professional? when was the last time you got updates on VS. one of the more recent ones was supposed to be better integration on Unreal things (though GENERATED_BODY() still throws a mini fit)
where are you putting your new classes source/ or are you splitting them further down into like a source/public/ and source/private/ ?
are you compiling from source, or are you using the Pre-Compiled Engine?
I’m running VS2022 Community 17.7.2 last updated on August 28th. I see 17.7.3 was just released, so I can try that but I’m not expecting a miracle.
My project is split private/public under /source/
Pre-compiled engine, since I haven’t modified it in any way.
that can totally happen due to what i’ve explained about unity builds.
and also on cpp syntax errors can propagate to other files depending on the includes as well.
probably the issue is in the file that includes playerstate, or on a file included before that include.
or maybe it’s not generating correctly the .gen.h files…
when you say
Except for the source files i copied over
can you share those files?
the code, not a screenshot.
the link that you shared, contains a solution by “disabling unity builds” which sounds like a very unfortunate way to patch it (and i wouldn’t recommend it), and also related to what i was mentioning. so it reinforces my idea that you have a syntax issue that is propagating.
clean up your includes and you might get a better error message, my recommendations are:
forward declare all you can, only include on .cpp
maybe you can try to order your includes to be engine > 3rd parties > plugins > your code.
Thanks for the suggestions, and agree that disabling adaptive unity is not the ideal solution. I won’t post my code since its several dozen files at this point, but I’ll give this a try.
I’m going back though all of my source files and doing some code cleanups in general, so I’ll pay close attention to the headers. I’m definitely not following the ordering convention you mentioned but that’s an easy fix.