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