Again: init variables in C++, then blueprints wipe it out.

Blueprints Resetting C++ Defaults After Crash How to Keep Them From Touching Anything in C++?

I posted a similar issue a couple of months ago, but this time it’s even weirder.

TL/DR: blueprints remove (set to null) MeshComponent set in c++, mesh is set to be c++ only not blueprint exposed.

Everything was working fine. I added components and variables in C++, created a static mesh, applied materials, all good. Then, due to an unrelated mistake (I compared a gameplay tag without checking if it existed), the Blueprint based on that class started crashing the editor (in C++ side of things) . I fixed the tag issue, but since then the Blueprint seems to be wiping out all the default values I set in C++ again.

The static mesh pointer, for example, is getting reset to null, even though logging in C++ shows it’s valid at first (class init). Then it’s suddenly null in the next log (after blueprints begin play). The mesh component isn’t even exposed to Blueprints.

This is a Blueprint child of a C++ base class. The Blueprint’s only job is to exist and maybe forward some its GamePlayTag names to the UI it should not be touching or overriding anything. Blueprint only reads few variables from C++. Did all this setup exactly for this reason, random wiping out variables after recompile of c++.

Is there a clean way to tell Blueprints to stay out of it completely? I’m worried about stability in the packaged build if things randomly revert to defaults or get wiped like this. Any way to make Blueprint children read-only or sealed so they don’t interfere with C++ data?

ps.
I tried to go with not exposing variables (that works) but static mesh component is visible in component tree, and blueprints happily set it to null ptr.

This is madness!

I just added UPROPERTY line, recompiled it. And blueprints do not set that to nullptr

	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "_K2G|CelestialBody")
	UStaticMeshComponent* MyPlanetMesh = nullptr;

then i reverted it all to:

    UStaticMeshComponent* MyPlanetMesh = nullptr;

Without UPROPERTY like it was before, now everything works again. Blueprints no longer wipe it.

So yes mesh component was there, blueprints just wiped this variable for some reason.

1 Like