Certain InstancedStaticMeshComponent instances don't render in the correct place when I add and remove instances in realtime?

So this is a very strange bug I’m running into, and would ideally like to find a workaround for in the meantime while it gets fixed in the engine, and would like to provide whatever is necessary to help.

I have an InstancedStaticMeshComponent (ISMC) that I’m adding and removing instances to/from while the game is running based on player input. The problem is, is whenever I remove certain instances, other instances will be rendered at the wrong location.

The most trivial example is as follows, with the returned indexes in brackets:
I will add the first instance [0], then the second instance [1], then the third instance [2]
I will then attempt to remove the first instance [0]
When I do, the third instance [2] starts rendering at the position of the second instance [1].

This is 100% reproducible and doing the same adding/removing sequence always causes the same instance so be rendered in the wrong location at the same points in the sequence.

EXCEPT: If I open the game as a standalone process, the misrendering of instances will change drastically, and instances are not rendered in the wrong places (to my knowledge), they are not rendered at all and only one instance is ever rendered at a time.

FINALLY: If I’m in the editor, I can solve the issue temporarily by going into the ISMC manually and either checking OR unchecking “Use Dynamic Instance Buffer”. It does not matter which it is set on before, or by default, simply toggling it causes the instances to render properly in the editor until I add or remove instances again.

Some other notes:

  • This 99% has nothing to do with the changing indexes of ISMCs in general (externally at least, there might be in issue with the fact that indexes change and multiple internal properties of the ISMC depend on those), I’m not using Hierarchical, and have verified using the toggling “Use Dynamic Instance Buffer” method above and verifying the transforms/indexes in the editor that the instances themselves are being removed/added in the spots they should be.
  • I have tried changing the StaticMesh, this happens with every different one I’ve used.
  • I’ve marked the Materials used on the StaticMeshes “Use With Instanced Static Mesh” or whatever that setting is.
  • I’m using the Binary Engine installed by the Launcher, 4.17.1
  • All of the adding/removing of instances are being done in C++, during the Tick() function of a subclass of AActor

I’m happy to provide more information, my source in a minimized project, a video, whatever would be helpful, just let me know.

EDIT More information and testing:

  • Toggling “Use Dynamic Instance Buffer” makes the misrendered instances appear correctly even while the game is PAUSED
  • Using a Hierarchical ISMC doesn’t fix the issue, but it does change the pattern of the misrendered instances, and when using an HISMC toggling “Use Dynamic Instance Buffer” has no apparent effect.
  • Using the ISMC’s MarkRenderStateDirty(), MarkRenderDynamicDataDirty(), MarkRenderTransformDirty(), MarkPackageDirty(), among several other similar functions have no effect, whether called in the Tick function of the ISMC owning actor, or delayed until the actor’s next frame Tick
  • Camera position or view, as well as ISMC Visibility, Show In Game, and other general visibility settings have no effect other than to hide the ISMC in its entirety, and when toggled again, causes the ISMC to reappear still having the misrendering issues.

As of 4.17.2, this bug still exists.

As of 4.18.1, this bug still exists, except now checking and unchecking “Use Dynamic Instance Buffer” doesn’t do anything or fix the misrendered instances.

1 Like

Fixed in 4.19

1 Like