IndexOutOfRangeException in GhostPresentationGameObjectSystem

Hi

DESCRIPTION
An IndexOutOfRangeException is thrown in the GhostPresentationGameObjectSystem’s OnUpdate method. This seems to occur only when the entity being removed is the last entity (since m_Entities[idx] is no long a valid element after its has been removed via RemoveAtSwapBack).

var state = ghostPresentationGameObjectStateFromEntity[entity];
int idx = state.GameObjectIndex;
if (idx >= 0)
{
    m_Transforms.RemoveAtSwapBack(idx);
    m_Entities.RemoveAtSwapBack(idx);
    var last = m_GameObjects.Count - 1;
    Object.Destroy(m_GameObjects[idx]);
    m_GameObjects[idx] = m_GameObjects[last];
    ghostPresentationGameObjectStateFromEntity[m_Entities[idx]] = new GhostPresentationGameObjectState{GameObjectIndex = idx};
    m_GameObjects.RemoveAt(last);
}
EntityManager.RemoveComponent<GhostPresentationGameObjectState>(entity);

This can be fixed by not updating the ghostPresentationGameObjectStateFromEntity component lookup when removing the entity at the last index:

var state = ghostPresentationGameObjectStateFromEntity[entity];
int idx = state.GameObjectIndex;
if (idx >= 0)
{
    m_Transforms.RemoveAtSwapBack(idx);
    m_Entities.RemoveAtSwapBack(idx);
    var last = m_GameObjects.Count - 1;
    Object.Destroy(m_GameObjects[idx]);
    m_GameObjects[idx] = m_GameObjects[last];
    if (idx != last)
    {
        ghostPresentationGameObjectStateFromEntity[m_Entities[idx]] =
            new GhostPresentationGameObjectState { GameObjectIndex = idx };
    }
    m_GameObjects.RemoveAt(last);
}
EntityManager.RemoveComponent<GhostPresentationGameObjectState>(entity);

STEPS TO REPRODUCE

  • Open the ClientSideAnimation scene from NetcodeSamples.
  • In the “Multiplayer PlayMode Tools” set “PlayModel Type” to “Client & Server”.
  • Set “Num Thin Clients” to 1.
  • Hit play button.
  • Hit “Client DC” button for the ThinClientWorld1 (disconnect the thin client).

This was tested in the following package versions:

  • 1.0.10
  • 1.2.0

Thank you for the bug report. Could you help me by opening a ticket and then write the incident number here?
You can do that from the editor Help > Report a Bug…
Then we can track it internally.

Logged an incident for this: IN-74090

1 Like

Thank you, we have received it in our team’s bug bag now.