ATanks incomplete class type error in Turrets.cpp (i.e. Tower.cpp) - The FIX


So I came across an error when trying to access Tank->:

float Distance = FVector::Dist(GetActorLocation(), Tank->GetActorLocation());

My code was correct, so i closed for the night and now this morning same error. So here is how i fixed it:
In UE5 IDE I went to Tools then clicked “rebuild visual studio project files”. After that i went into VS and removed all the Tank code lines in the Turrets.h and Turrets.cpp files. I then made sure i closed my UE5 IDE, and “Cleaned the solution” then “Rebuilt Solution”. After this i added back the Tank code i.e. the forward declare and distance math. It was then able to compile properly with no more errors!

I hope this helps someone else who also had this issue!

Are you building the editor solutions from your IDE?

I found with VSC and living coding I did have this issue after closing the editor, and having to build a bit more often. However, I also found if you’re using the TookTanksEditorDevelopment build, and after compiling from VSC, if you hit the recompile button in the UE editor, it should reattach all your classes. I found myself compiling from VSC/VS then recompiling the c++ code in the editor to reattach all the subcomponents and parent classes.

If you look in the log, you can often see during this process that during the second compile (from within UE) that the .obj files for your code has still been modified - i.e changes still in flight. Give that a try and see if it doesn’t fix the objects/subobjects coming off.

As I understand it, you’ve got to rebuild/recompile whenever youre adding new objects.

Rebuilding project files is usually for when you want to pass an updated .sln file to Visual studio. I found I stopped having this issue so much after switching to VS2022.

Hope this helps.

Hi ,

I was using live coding. With a compile through VS every now and then. The issue never cropped back up again. Only happened once.

Privacy & Terms