Download

UStaticMeshComponent not rendering mesh

i have an object that creates tiles using static mesh components.

The generation code is as follows:



            UStaticMeshComponent* tile = NewObject<UStaticMeshComponent>(this, componentName);

            if (tile != nullptr) {
                tile->SetSimulatePhysics(false);

                tile->SetupAttachment(RootComponent);
                tile->SetStaticMesh(meshToSpawn);
                tile->SetRelativeLocation(spawnOffset);            

            }
            else {
                UE_LOG(LogTemp, Error, TEXT("StaticMeshMapGenerator failed to create tile component at coords %dx%d !"), rowIndex, colIndex);                                
            }

this seems to correctly generate a component for each tile, but the mesh doesn’t seem to be visible…

each component would seem to have a correct location ,mesh and material (see screenshot), but nothing appears on screen.

What am i missing?

screen.jpg

I think you may need to mark the renderstate as dirty for it to update.

hey @rubenst thank you for the feedback; could you please give me some more info on how to do that ?

thank you

EDIT:
i found iinformations, and altered the code as:


                tile->SetupAttachment(RootComponent);
                tile->SetStaticMesh(meshToSpawn);
                tile->SetRelativeLocation(spawnOffset);
                tile->MarkRenderStateDirty();

but nothing happened :frowning:

EDIT2:
bOnlyOwnerSee and bOwnerNoSee are both set to false

update for future readers:
thanks to a discord user, the missing part was


tile->RegisterComponent();


in the tutorial here: https://docs.unrealengine.com/en-us/…s/Components/1 sadly there is nothing about it, so i guess it’s not updated, or somehow misleading.