As for the second part of your questiong regarding the disappearing tracks
Same problem I’m fighting against. The C++ component classes derived from StaticMeshComponent lose their SM when recompiling. Happens with turret and barrel as well.
It seems, that it only happens, if the .h file is changed (but no guarantee for this). Sometimes, the components even get into such a bad state, that the mesh even gets lost when just restarting the UE4Editor without any compilation of C++ code. In that case, the components have to be deleted and added in again.
There has been discussion about this being caused by changing UPROPERTY values to private. See
https://answers.unrealengine.com/questions/816388/view.html and the referenced issue link
https://issues.unrealengine.com/issue/UE-63298
Other discussions are about the Hot Reload feature making things fail. There’s quite a lot discussion on that topic.
But I think, there’s another problem, because changing a working .h file just with a comment also leads to that loss.
It is getting more and more confusing. For example, I found that other variables get lost, as you say. For example, I had situation, that a changed Collision Preset value was lost after reopening the editor. BUT: this did not get lost, if I had a Physical Material assigned as well. So both did not disappear, but Collision Preset w/o Physical Material got lost. Only way out here: remove and readd components.
I am still experimenting. See my test project for this on https://github.com/herb64/UE4-SMC-problem
With this project, I can reproduce the vanishing mesh on my system. But strange enough: cloning onto another system - and no error. So I think, this might also be related to some stuff being held in precompiled headers or whaterver. Maybe from time to time its useful to delete all unnecessary files and open the project from scratch, rebuilding the .sln etc…
My current workaround
In the test project above, you’ll find a description of my workaround by simply implementing the class constructor and loading the required static mesh here. This works for me at the moment, although it is realy ugly . And it is not helping in any case, at some times, things still get screwed up.
Here’s an example from my code for the tracks:
// Just switch workaround off by commenting this
#define WORKAROUND
/*
* W O R K A R O U N D F O R V A N I S H I N G S T A T I C M E S H
* Set static mesh within the constructor manually
*/
UTankTrack::UTankTrack()
{
#ifdef WORKAROUND
// We simply use the Engine Cone Basic Shape
static ConstructorHelpers::FObjectFinder<UStaticMesh>SM_Track(TEXT("/Game/Tank/tank_fbx_Track"));
UStaticMesh* TrackMesh = SM_Track.Object;
if (TrackMesh != nullptr) {
UE_LOG(LogTemp, Warning, TEXT("Set track mesh %s"), *TrackMesh->GetName());
this->SetStaticMesh(TrackMesh);
}
else {
UE_LOG(LogTemp, Error, TEXT("Could not set static mesh to component"));
}
#endif
}
I hope this helps a little bit with the static mesh…