Random compile errors?

Hello.

I’ve been using the engine for a while, mostly learning what it has to offer and how to use it. What I have noticed is that I often get strange errors from seemingly working code. This happens usually when I want to create new files or add includes to files.
I may move a file to another location after having created it and suddenly I get errors that the file may be missing. Sometimes a duplicate of the file seems to be created where the original was before I moved the file.

Another case I had just now was when I created a new header file and then added an empty class as the following:



.h

#pragma once

#include "TestClass.generated.h"

UCLASS()
class UTestClass : public UObject
{
    GENERATED_BODY()
};

.cpp

#include "SomeProject.h"
#include "TestClass.h"


It compiled fine just as it should. I then proceeded to delete the source file which gave an error that the source file could not be found which is also reasonable. Next I deleted the class from it at which point only the #pragma once and #include “TestClass.generated.h” were left and now I got the c1083 error with no such file or directoy. Following this I pressed ctrl+z to undo it and compiled again. You would now expect that I would again get the error that the source file is missing but no. Now it sticks with the c1083 error. After this I removed it again and now replaced it with a struct like the following:



.h

#pragma once

#include "TestClass.generated.h"

USTRUCT()
struct FStuff
{
    GENERATED_USTRUCT_BODY()
};



Now it suddenly compiles just fine with no errors.

On another occasion yesterday I suddenly got some unauthorizedaccess exception on some file which I don’t remember the name of that wouldn’t go away. Finally after trying different things I ended up deleting the Binaries/build/Intermediate folders and used the .uproject file to regenerate visual studio files and the open up VS after which it compiled without any problem.

Earlier as well I created a header file without any source file and added several USTRUCTs and UENUMs to it. It worked fine and I could use them as function parameters in other classes. However the moment I used a UFUNCTION(BlueprintCallable) macro on a function with a struct in it I got the “OtherCompilationErrors(5)” or something like that. I figured it might happen because I had multiple utypes in same file and so I split them up into separate header files. However after this each file gives the c1083 error saying the Cannot open include file: … . No such file or directory.
From what I have experienced I tried just for “fun” to put things back how they were again with the structs and enums in one file again and removed the UFUNCTION macro. The c1083 is still there and not only that every new header file I create gives the error regardless of what I add to it or where I place it. I am still stuck at this right now.

I’ve usually gotten by either by deleting a file completely and created a new in the proper place or as mentioned deleting the Binaries/build/Intermediate but I have become really tired of all this and so it has let me to create this messy post.

I was wondering if others are getting errors like these regularly and if there are any ways of addressing them properly without having to delete folders? I may be missing out on something or not understand something properly.

Would appreciate if somebody could enlighten me thanks.

#UE Version 4.9.2 (download/install with EG launcher) - VS2013 prof

Bear in mind that Unreal manages your project NOT Visual Studio. Anytime you change what files are in your project or where they are located you absolutely should regenerate the project files before continuing or else you are in for a world of hurt. Additionally Unreal does a lot of preprocessing stuff on your files and especially headers, before compilation even begins so that is also a potential problem point if you don’t have everything just right.

So I should use the “Generate vs project files…” whenever I make structural changes to my project I assume?
Seems to work without deleting the folders yeah.

Although it might be a bit off topic but since I mentioned it I was wondering what is causing the issue with the UFUNCTION macro.

Basically I am creating a small network project to learn the networking stuff in UE and I have this:




NetworkTypes.h

#pragma once

#include "NetworkTypes.generated.h"

UENUM(BlueprintType)
namespace ELoadMapType
{
	enum Type
	{
		Local,
		Browse,
		Travel
	};
}

USTRUCT(BlueprintType)
struct FLoadMapParams
{
	GENERATED_USTRUCT_BODY()

public:
	UPROPERTY()
	FString MapName;
	//UPROPERTY() cant be UPROPERTY()?
	ELoadMapType::Type LoadType;
};


NetworkGameinstance.h

#pragma once

#include "TestNetworking.h"
#include "Engine/GameInstance.h"
#include "NetworkGameInstance.generated.h"


/**
 * 
 */
UCLASS()
class TESTNETWORKING_API UNetworkGameInstance : public UGameInstance
{
	GENERATED_BODY()

public:
	......
	
	//UFUNCTION(BlueprintCallable, Category = "MissingCategory") gives errors
	bool LoadMap(const FLoadMapParams& LoadParams);
};



First problem is the UPROPERTY() is unusable on the UENUM.
Second is that the UFUNCTION macro on the LoadMap gives errors.

For both of these I just get: Error 1 error code: OtherCompilationError (5) C:\Users\Jonas\Documents\Unreal Projects\TestNetworking\Intermediate\ProjectFiles\Error TestNetworking

Also whenever I come across this I have a bit of trouble figuring it out. Is there some other output thing that gives more information about what is going wrong?

NOTE: Without the UPROPERTY() and UFUNCTION() macros everything compiles and works.

See this: Unspecific/Unhelpful build errors? - C++ Gameplay Programming - Unreal Engine Forums about how to see the hidden error which will help in general.

For this specifically, there are some rules on how enums have to be handled in order to be properly exposed to the Reflection system. Do some searching in the docs, I don’t recall the specifics off the top of my head.

I tried running the command but it gives me this:

C:\WINDOWS\system32>"“C:\Program Files\Epic Games\4.9\Engine\Build\BatchFiles\Build.bat” ThirdPersonEditor Win64 Development “E:\Unreal Projects\ThirdPerson\ThirdPerson.uproject” -rocket"
‘""C:\Program’ is not recognized as an internal or external command,
operable program or batch file.

I’m not familiar with cmd usage as I hardly ever need to touch it but I assume I need to write something beforehand? Like you use Start “…” when starting a process?

Drop the outside set of quotes so that it looks like:
“C:\Program Files\Epic Games\4.9\Engine\Build\BatchFiles\Build.bat” ThirdPersonEditor Win64 Development “E:\Unreal Projects\ThirdPerson\ThirdPerson.uproject” -rocket

This is really nice. Have had trouble with it before and not knowing the exact problem. Have usually figured it out but this makes it much easier.

For these problems it was as I had suspected with the enum. It has to be one of the two others that does not use the namespace thing. As for the UFUNCTION() it did not recognize the FLoadMapParams as a struct. I remembered something about filenames I read a while back so I changed the file name to be identical to it and it works now.

It is quite annoying you have to make a new file for each enum/struct you have if you want to use them in UFUNCTIONS. The funny thing is before I used the UFUNCTION and had them both in same file I could still use them in blueprint.

Thanks a lot this has been quite helpful.