Download

HISMC with programmatically set mesh does not play nice with navmesh.

UE version 4.23.1.

TL;DR: HISMC’s function SetStaticMesh seems to have buggy behaviour when interacting with navmesh.

Explanation:

I have HISMC called **Instancer **in actor blueprint called TestInstancer_BP. It is very simple blueprint, just to test problem I have.


It creates one instance of mesh (test floor tile) for testing in function BuildDynamically.

It is called in Event BeginPlay.

I can either:

  • Set static mesh (yes, it has collision configured) in editor in advance (then node SetStaticMesh is disconnected)…


  • …or set it programmatically in blueprint (then nothing is set in editor).


I need second case for my game with procedurally generated levels - I can’t predict in advance what will be needed, and even if I could, I still need to create HISMCs dynamically for all used combinations of mesh + material(s).
Problem is that in second case navmesh says “I don’t see anything because bleep you”. Navmesh is already configured to update fully dynamically (appropriate project settings).

Working example (static mesh set in editor) - as you can see, navmesh generates properly (so we can be relatively sure that navmesh in general is configured correctly, same with mesh’s collisions etc):


Not working example (nothing set in editor, static mesh set programmatically in blueprint, rest is exactly same):


What I can do to rectify that? It is pretty obvious that when I set Instancer’s static mesh in editor in advance, more things happen internally than just calling SetStaticMesh. Experiments with setting static mesh first in editor and then setting different mesh programmatically proved that - navmesh reacts like collision is provided by previous mesh (one set in editor).

It is very strange, since collision works properly otherwise in way matching that mesh - if I try to walk into that thin wall, I stop.

It seems to be buggy behaviour.

Is there any workaround? I suspect that maybe I should call some additional functions (no idea which ones) of Instancer or mesh itself or something else. Anybody knows?

Workaround found. If anyone has same problem: in parent blueprint (let’s call it InstancerManager) after spawning blueprint containing HISMC (let’s call it Instancer) you must first set mesh and then call AttachToActor (thats critical part) where ParentActor is Self. In other words: attach Instancer to InstancerManager. It is not clear why it works (maybe it refreshes something internally), but I don’t care.

Actual example from my game:

Instancer blueprint is named here BP_MeshInstancer. Mesh is resolved and set in function Configure based on data in ActorStruc.