Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2005
    Location
    Independence Mo.
    Posts
    380

    TerrainDemo ArgumentOutOfRangeException

    I get A ArgumentOutOfRangeException: Argument is out of range every time move around in game. it happens when it adds or remove patch form the game. here the the error I get

    ArgumentOutOfRangeException: Argument is out of range.
    Parameter name: index
    System.Collections.Generic.List`1[_CodeBase.Demos.TerrainPatch].get_Item (Int32 index)
    _CodeBase.Demos.TerrainDemo.HandleTerrainUpdates () (at Assets/_CodeBase/Demos/TerrainDemo.cs:147)
    _CodeBase.Demos.TerrainDemo.Update () (at Assets/_CodeBase/Demos/TerrainDemo.cs:57)
    GameManager.Update () (at Assets/_Scripts/GameManager.cs:31)

    the problem seems to be in the HandleTerrainUpdate method in the patchToRemove .count if Statement
    Code:
                if (patchesToRemove.Count > 0)
                    for (int i = patchesToRemove.Count - 1; i >= 0; i++ )
                    {
                        var terrainPatch = patchesToRemove[i];
    
                        if (PatchUpdatTimer <= 0 &&
                            (Mathf.Abs(CurrentPatchLocation.y - terrainPatch.Offset.y) > tileSideCount ||
                             Mathf.Abs(CurrentPatchLocation.x - terrainPatch.Offset.x) > tileSideCount))
                        {
                            terrainPatch.Destory();
                            assetSweepCounter++;
                            PatchUpdatTimer = patchUpdateDelay;
                            patchesToRemove.Remove(terrainPatch);
    
                            if (assetSweepCounter >= tileSideCount * 2 + 1)
                            {
                                Resources.UnloadUnusedAssets();
                                assetSweepCounter = 0;
                            }
    
                            break;
                        } 
                    }

  2. #2
    Join Date
    Apr 2009
    Location
    Rochester, MN
    Posts
    179
    for (int i = patchesToRemove.Count - 1; i >= 0; i++ )

    your problem is your adding not subtracting try:

    for (int i = patchesToRemove.Count - 1; i >= 0; i-- )

  3. #3
    Join Date
    Jul 2005
    Location
    Independence Mo.
    Posts
    380
    Yep that was it Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •