Project crashes upon compiling

You have to be a bit more specific before anyone can help you. Where does your program crash? What error messages are you getting? what’s your debug output log telling you? what line of code are you getting the crash on?

Hello fellow developers, over the past few weeks I have been unable to compile code in my projects without the entire thing crashing on me. The code I’m trying to compile is super basic, I create a new c++ actor class and give it a shape component and static mesh component. However, when I try to compile the code the project crashes and if i try to open it again it will crash instantaneously. I have tried this over and over again with different projects and different code but no matter what I get the same results. Now I’m relatively new to Unreal as I just started using it back in April, but in the beginning my projects would compile and run just fine. The problem didn’t occur until June when I took about a two week break from Unreal due to high school finals and such, and ever since I came back I’ve been faced with these crashes. Whats even worse is that when I tried to write code to projects I created before my little break they crashed as well and are now unusable. Does anyone know what I need to do to resolve this? Has anyone else experienced this issue?

Go to your projects folder, find the “Saved” folder, then look for the “Logs” folder, and find the most recent log. Scroll all the way down the bottom and then start scrolling up. Look for the very last error. This should give you a hint on what is causing the issue for you.

Okay, that’s a bit more helpful. That means one of your code classes has a constructor which is trying to use an object initializer which is the incorrect one (obviously). So, there’s a chance that your log file might give you an indicator or hint at which constructor that is. You should be using FObjectInitializer in your constructors, so make sure you see that. You should also be on the lookout for creating actors using NewObject<>, or using NewObject<> to create actors. You can start to narrow down the source of your problem now because you have a starting point to work from: the constructor in one of your classes is wrong.

No matter what code I put in I get kicked out of my project and faced with the unreal engine crash reporter when I press the compile button. The project crashes before it finishes compiling so I don’t even get a chance to see the debug log or any error messages. Once the crash occurs and I try to reopen the project it just immediately puts the crash reporter in my face so I can’t even open them again. I wish I could be more specific but that’s really the best I can do.

Okay so the last error says:
“Fatal error: [File:D:\BuildFarm\buildmachine_++UE4+Release-4.11\Engine\Source\Runtime\CoreUObject\Private\UObject\Obj.cpp] [Line: 85]
Using incorrect object initializer.”
But I’m not quite sure what it means, obviously I did something wrong with initializing the object but it says its on line 85 and my code for the class definitely didn’t have 85 lines so I’m a little confused

Well the good news there is that I only made one class in the last project that crashed so clearly that’s where my issue is. Now I know this might be a rookie question, but exactly how do I use FObjectInitializer? Do i just declare it in the classes constructor or is there more to it?

Whenever you create a class, you need to create the default constructor which inherits from UObject. Here is the general template of what your source and header files should look like:
Header file:

class AMyClass : public AActor
{
     GENERATED_CLASS()
     
     public:
     AMyClass(const FObjectInitializer& ObjectInitializer);
};

CPP File:

AMyClass::AMyClass(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
{
///can be empty
}

It’s really important that you call “Super(ObjectInitializer)” so that the parent class can do its thing if it needs to.

Alright just did all that and my project finally compiled! Thanks for your help and your time Slayemin, and good luck in all your coding endeavors(not that you need it).