My C++ classes disappear after reopening the project. Why?

I have created the actor MyEarth which loads a staticmesh from Content Directory and the class MyGameModeBase (derived from GameModeBase) which spawns an instance of MyEarth in a position. Everything works fine, the actor appears as expected.
But,after saving eveything,when i reopen the project, my c++ classes MyEarth and MyGameModeBase are no longer in the C++Classes Folder of the Content Drawer of the Editor,and when i run the project,nothing appears and no MyEarth actor in the Outliner.
Obviously the class code is there,in the Source Directory of the project.
Why does this happen? Similar problem in a my previous post with blueprint.
I find NO solution. Maybe a bug ? Thanks in advance !!! This problem is a stop with Unreal Engine for me.
This is part of the code:

MyEarth.cpp:

AMyEarth::AMyEarth()
{

PrimaryActorTick.bCanEverTick = true;
root = CreateDefaultSubobject<USceneComponent>(TEXT("Root"));
SetRootComponent(root);
earth = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Earth"));
static ConstructorHelpers::FObjectFinder<UStaticMesh>MeshAsset(TEXT("StaticMesh'/Game/earth.earth'"));
earthMesh = MeshAsset.Object;
if (MeshAsset.Object)
{
	UE_LOG(LogTemp, Warning, TEXT("MESHOBJECT NOT NULL "));
	earth->SetStaticMesh(earthMesh);
            earth->SetupAttachment(root);
}
else
	UE_LOG(LogTemp, Warning, TEXT("MESHOBJECT IS NULL"));

}
/////////////////////////////

MyGameModeBase.cpp:

void AMyGameModeBase::BeginPlay()
{
Super::BeginPlay();

AMyEarth* obj = (AMyEarth*)GetWorld()->SpawnActor(AMyEarth::StaticClass());
if (obj)	
   obj->SetActorLocation(FVector(-100, 350, 500));

}

4 Likes

Are you launching through the launcher or are you launching through your IDE? Try deleting your intermediate and binaries folders, and then try launching the project again. It will have to rebuild your code but it should work. If you are using your IDE to launch, make sure you’re building using the Development Editor configuration, because this is what the launcher uses.

15 Likes

same here. I’ve updated to 5.0.1 today. Didn’t experience something like this before. :frowning:

I’m using Live Coding in UE 5 since Early Access. I don’t think that’s the problem. Live Coding worked fine in Preview builds also (from Epic Launcher) and I don’t have any issues with 5.0.1 either. I think further investigation is needed as Live Coding might not be the culprit in my opinion.

Thank you Zeaf. I launch the project from the launcher and i use the ide to write c++ code.
I have deleted intermediate and binaries folders,then the launcher asks me if i want to rebuild the project. After that,when i open the project,my classes reappear again but when i open visual studio,the editor tells me that the project does not exist.
So,after deleting intermediate and binaries folders and rebuilding

  • i close ide and project,and then open again the project
  • In World Settings/ GameMode override,i select MyGameModeBase (derived from GameModeBase),this is fundamental!
  • if i open visual studio,the project is there,with all the code.
  • AND EVERYTHING WORKS
2 Likes

One more thing you can do if you find yourself opening the project from the launcher is to go to Edit → Editor preferences, search for “Force compilation” and tick the box there. That way your project will automatically compile the code if there are any changes any time you launch it from the launcher or by double clicking the uproject file

10 Likes

Thank you Zeaf :+1: :+1: :+1:

Small update. I forgot to write that before opening visual studio you need to Refresh Visual Studio Project from Tools of Unreal Engine Editor,otherwise visual studio keeps saying that the project doesn’t exist.
Thanks :wink:

1 Like

In my case, i just pressed compile button and then it compiled, then all the classes were visible again.

1 Like

I have followed the steps here, but I am still missing several C++ files and also folders. I do have live coding enabled. Deleting binaries and intermediate folders, then regenerating the VS file does not help at all for me. Interestingly this is not happening to my colleague. Both of us on 5.1,

So to be short, I faced the same problem and found a solution. The first tip is always to Open the project from the launcher. For some reason, opening a project from IDE make the compiling process weird.

When you open the project, you may find none of your C++ code available! At this point, you should hit the C++ compile button to get your codes back.

But still, the changes you made to your level may not be available. Then you have to Build the level, and everything will be where you left it before.

I don’t know how to stop this from happening. But it should be enough to save your efforts. Also, take note that after applying this, all the changes you lost could return, not only the last one.

I hope this work for you guys as well.

1 Like

this works for me!! thanks a million!

This worked for me on UE5.3 without needing to delete the intermediate and binaries folders. Thank a lot!!

I have regenerate the uporject, but it does not work. I have checked the Show C++ Classes. But I only see the Content, and Engine foler in the Root.

Thx, Zeaf.
I just faced the same problem in 5.4.3 and your solution works.
I think this is obviously a bug and needs to be fixed quickly by Epic.

I found the root issue is from live coding. Everytime I relaunch UE5.4 with live coding enable, all my c++ will disappear. But my c++ still appear if live coding is disabled. Defenitely bug and Epic need to fix this asap.