Spawned actors visible after stopping, not during play

Hi

I’ve created a class with a function InitializeModel, that is exposed to blueprint. In this function some AStaticMeshActors should be spawned, but I cannot see them during play, I need to stop the game for them to appear. If I stop the game and start it again they’re still visible. In blueprint I’m using BeginPLay event to trigger “create object from class” then running the InitializeModel on it,

I’ve tried placing some prints in InitializeModel and I know that it runs properly just after beginPlay, but models are invisible just after that, they’re visible after stopping, and later, after starting play again.

In header file, as public field of this class, I’ve got:


UPROPERTY()
TMap < FString, UStaticMesh*> mMeshes;

In Cpp :


MyClass::MyClass()
{
    static ConstructorHelpers::FObjectFinder<UStaticMesh> StaticMeshFinder(TEXT("StaticMesh'/Game/box.box'"));
    mMeshes.Emplace("box0", StaticMeshFinder.Object);
}


bool MyClass::MyClass()
{
    bool result{ false };
    ...]
    // Preparation of scene
    float unitsScale{ 100.0f };
    for (int i = 0; i < m_numberOfBlocks; i++)
    {

        FTransform transform;
        FVector vec;
        FRotator rotation;
        FActorSpawnParameters SpawnParams;
        AStaticMeshActor* NewElement = GetWorld()->SpawnActor<AStaticMeshActor>(vec, rotation, SpawnParams);
        NewElement->GetStaticMeshComponent()->SetStaticMesh(mMeshes"box0"]);
        NewElement->SetActorHiddenInGame(false);
        NewElement->SetMobility(EComponentMobility::Movable);

        m_elementsList.Add(NewElement);
}
return true;
}

All I want to do is to place some simple meshes in scene at the start of playing. I’d like to be able to move them later. So if that’s not the correct way to do this then please, show me the correct way,

Regards