GPU Instancing objects disappearing
No matter what I do, I have inconsistent results with GPU instancing. The first few seconds all is well. Then some objects disappear, until no object is left. Sometimes objects reappear, for instance when they're interacted with (collider). Sometimes objects reappear due to camera rotation. They always disappear a few moments after.
The problem seems to occur when I update the position every frame:
var positions = new Vector4[_objects.Count];
for (var i = 0; i < _objects.Count; i++) {
positions[i] = new Vector4(
_objects[i].transform.position.x,
_objects[i].transform.position.y,
_objects[i].transform.position.z,
1
);
}
_positionBuffer.SetData(positions);
At least, I get consistent behavior if I call my UpdateBuffers method only on start. Any idea how I make my objects move?
What I tried until now:
DrawMeshInstanced
DrawMeshInstancedIndirect
Default material/shader with "Enable gpu instancing" enabled
Custom shader, copied from documentation example
I'm running on the latest 2018 stable.
Answer by HappyStoner · Jun 04, 2018 at 06:51 AM
Turned out to be the following. Due to me rendering the objects on a specific spot in the world, I totally missed the fact that the gameobjects were falling through the ground. When they reach a certain distance, unity decides it should not render the objects anymore.
Your answer
Follow this Question
Related Questions
DrawMeshInstanced has bad perfomance on some Android devices 0 Answers
DrawMeshInstanced is not giving specular highlights 0 Answers
Which one to believe? 0 Answers
Making a custom shader use GPU Instancing? 1 Answer
PostLateUpdate.FinishFrameRendering 2 Answers