Crash in game mode with InstancedStaticMesh as RootComponent

Hi community,

I am new in Unreal programming so please forgive the probably evidence of my question.

I am doing some tests with InstancedStaticMesh that seems to work quite good in editor mode, but crash in GameMode (Play in the editor).
Could you explain to me why please?

Crash happens when i replace the Floor->AttachTo(RootComponent) by RootComponent = Floor;

Is it forbidden to have an InstancedStaticMesh as RootComponent?
The crash seems to happen when trying to get a Body for something (debug assertion).

Thanks for your time.

UCLASS()
class TEST_API AMeshSet : public AActor
{
	GENERATED_BODY()
public:

	/** a static Mesh  */
	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Test)
		UInstancedStaticMeshComponent* Floor;


	/** a static Mesh  */
	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Test)
		UInstancedStaticMeshComponent* Pillar;

	AMeshSet(const FObjectInitializer& ObjectInitializer);

	UFUNCTION(BlueprintCallable, Category = Dungeon)
	void Reconstruct();

};


AMeshSet::AMeshSet(const class FObjectInitializer& PCIP)
: Super(PCIP)
{    
	Floor = PCIP.CreateDefaultSubobject<UInstancedStaticMeshComponent>(this,TEXT("Floor"));
	static ConstructorHelpers::FObjectFinder<UStaticMesh> floorStaticMesh(TEXT("StaticMesh'/Game/StarterContent/Architecture/Floor_400x400.Floor_400x400'"));
	Floor->StaticMesh = floorStaticMesh.Object;
	// RootComponent = Floor;
	Floor->AttachTo(RootComponent);

	Pillar = PCIP.CreateDefaultSubobject<UInstancedStaticMeshComponent>(this, TEXT("Pillar"));
	static ConstructorHelpers::FObjectFinder<UStaticMesh> pillarStaticMesh(TEXT("StaticMesh'/Game/StarterContent/Architecture/Pillar_50x500.Pillar_50x500'"));
	Pillar->StaticMesh = pillarStaticMesh.Object;
	Pillar->AttachParent = RootComponent;

	Reconstruct();
}

InstancedStaticMesh purpose is to render multiple instance of the same static mesh efficiently. It would make for a poor RootComponent in my opinion!

Maybe what you want to do is to have a StaticMeshComponent as your root?

Try UStaticMeshComponent instead of UInstancedStaticMeshComponent.

Hi Michael,
Thanks for answer.

I use InstancedStaticComponents to instantiate StaticMeshes in the Reconstruct function.

Putting this kind of component as root crash the game (not the editor).
I have no use of StaticMesh as root but following your advice, i tried:

  • A empty StaticMeshComponent but it crashes too.
  • A USceneCompoent, as is (used like a empty) and it works as Root.More it resolves some instanciation performance problem i had with my first solution (No RootComponent defined)

Thanks for putting me in the rails.