Components get null'ed on blueprint compile (UE 5.0.2)

I’ve made an actor (AChessBoard) which spawns a “chess” board based on a size parameter, while still in the blueprint editor:

image
image

I’ve achieved this via the PostEditChangeProperty - dragging the Board Side Size slider works as expected.
The squares are declared as

UPROPERTY()
TArray<UChildActorComponent *> Board;

(Each UChildActorComponent holds an instance of AChessPosition)

However, when I press the blueprint editor Compile button, all the UChildActorComponent * become nullptr, the pieces disappear, and the Board TArray is not resized - I can still iterate through the original number of pieces, which are all nullptr at this point.

I tried changing the declaration of the Board to

UPROPERTY(Instanced)
TArray<UChildActorComponent *> Board;

which gets me closer to the desired result (after BP compile):

image

Each UChildActorComponent gets reconstructed, but without the material I applied to the instance of AChessPosition on it (after creating the instance, not in its constructor). The mesh is declared in AChessPosition:

UPROPERTY(VisibleAnywhere, Category = Chess)
UStaticMeshComponent * Mesh;

I tried adding the Instanced specifier here also, but it didn’t work.
I tried not having a TArray in AChessBoard, with just a single UChildActorComponent - but it also gets null’ed on BP compilation.

I tried reading the engine source to no avail - I got the vague idea that when compiling, Unreal:

  • saves object UPROPERTY marked properties (how ?)
  • destroys the objects
  • performs the compilation
  • recreates objects based on the cache (?)

I’m probably completely wrong, though :smiley:

Am I going in the right direction, or be there dragons?

Source code

1 Like

Bump.
I’m now hooking into PostInitProperties, which fires after a BP compilation, to mark my board as stale. That’s not a great solution, though - the TArray should be empty.