I want to adjust the ScreenSize of LOD in Runtime

My environment is as follows

UE5.3.2
Twinmotion2023.1.2

I am creating an UnrealEngine application that uses DatasmithRuntime to display udatasmith files exported by Twinmotion.
When loaded in DatasmithRuntime, the tree and human models placed in Twinmotion immediately display rough models due to the large LOD ScreenSize values.

The following screenshot is an example of a tree model loaded.
Due to the large ScreenSize value, this mushroom-like model is immediately displayed.

For this reason, I have written the following code in C++ to adjust the ScreenSize of the LOD of the StaticMesh, but it is not working.

void ULaplaceUtils::SetLOD(UStaticMesh* Mesh)
{
	Mesh->bAutoComputeLODScreenSize = false;
	int32 NumLODs = Mesh->GetNumLODs();
	if (NumLODs >= 4)
	{
		Mesh->GetSourceModel(0).ScreenSize = 0.5;
		Mesh->GetSourceModel(1).ScreenSize = 0.1;
		Mesh->GetSourceModel(2).ScreenSize = 0.05;
		Mesh->GetSourceModel(3).ScreenSize = 0.002;
	}
}

When I check in EditorPlay, the ScreenSize is reflected in the loaded StaticMesh, but it is not reflected unless I change the ScreenSize on the Editor, even slightly.
For example, changing the ScreenSize of LOD0 from 0.5 to 0.51.

How can I reflect the ScreenSize change in the C++ code?
Or do you have any good ideas on other ways to avoid displaying the mushroom-like model above?

https://github.com/EpicGames/UnrealEngine/blob/5.3/Engine/Source/Editor/StaticMeshEditor/Private/StaticMeshEditorTools.cpp#L4151-L4209

I was able to change the ScreenSize dynamically by writing the following code referring to the above code.

void UMyUtils::SetLOD(UStaticMesh* Mesh)
{
	int32 NumLODs = Mesh->GetNumLODs();
	
	if (NumLODs >= 4) 
	{
#if WITH_EDITORONLY_DATA
		Mesh->bAutoComputeLODScreenSize = false;
#endif

#if WITH_EDITOR
		Mesh->GetSourceModel(0).ScreenSize = 0.5;
		Mesh->GetSourceModel(1).ScreenSize = 0.1;
		Mesh->GetRenderData()->ScreenSize[2] = 0.05;
		Mesh->GetSourceModel(3).ScreenSize = 0.002;
#endif
		Mesh->GetRenderData()->ScreenSize[0] = 0.5;
		Mesh->GetRenderData()->ScreenSize[1] = 0.1;
		Mesh->GetRenderData()->ScreenSize[2] = 0.05;
		Mesh->GetRenderData()->ScreenSize[3] = 0.002;

		{
			FStaticMeshComponentRecreateRenderStateContext ReregisterContext(Mesh, false);
			Mesh->Modify();
		}
  }
1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.