Runtime InstancedStaticMesh Navigation problem

Hi, I Am working with instanced static mesh, spawn the components and fill them in game, everything work fine but navmesh ignore the components, if i run the code in editor the navmesh work correctly.
how do I make sure navmesh doesn’t ignore the UInstancedStaticMeshComponent created at runtime?

StaticInstancesComponent[i] = NewObject<UInstancedStaticMeshComponent>(this, UInstancedStaticMeshComponent::StaticClass(), FName(String));
		if (!StaticInstancesComponent[i])
			return;
		StaticInstancesComponent[i]->RegisterComponent();
		StaticInstancesComponent[i]->AttachToComponent(RootComponent.Get(), FAttachmentTransformRules::KeepWorldTransform);
		StaticInstancesComponent[i]->CreationMethod = EComponentCreationMethod::Instance;
		StaticInstancesComponent[i]->SetStaticMesh(StaticInstancesArray[i].StaticMesh);
		StaticInstancesComponent[i]->SetMobility(EComponentMobility::Movable);
		StaticInstancesComponent[i]->SetCollisionProfileName(FName("BlockAllDynamic"));
		StaticInstancesComponent[i]->SetCanEverAffectNavigation(true);
		this->AddInstanceComponent(StaticInstancesComponent[i]);

		StaticInstancesComponent[i]->AddInstances(StaticInstancesArray[i].Transform, false, true);
		StaticInstancesComponent[i]->SetWorldLocation(FVector(0));

I’m using Invoker with Runtime Generation Dynamic


Howdy malock89, welcome back and thank you for posting.

The concern may be due to your navigation settings. I found a relevant thread that may provide more help. Its discusses changing your navigation settings. In UE5, I believe, you may want this set to Dynamic.

I hope this helps.

Thanks, i have set the runtime generation to dynamic and checked generate navigation only around navigation invoker .
I notice that if i press play, f8, than move the instances, the navmesh start to work on them too.
then I found a partial solution forcing the navmesh to update the instancedStaticMeshComponent toggling SetCanEverAffectNavigation(already set to true) after the begin play

StaticInstancesComponent[i]->SetCanEverAffectNavigation(0); StaticInstancesComponent[i]->SetCanEverAffectNavigation(1);

I don’t find this solution very clean but it work now

I guess calling RegisterComponent(); at the end would fix the problem. its even more logical.

Must be careful not to call AddInstances() before RegisterComponent(), this will crash the engine. However even calling it at the end does not solve the problem