#Hello i m working on a small project and

1 messages · Page 1 of 1 (latest)

pearl otter
#

i added a Debug.Log in my UnitController script and the List exists and has all the accessible tiles but when i get it from my AutoEnenmy script it doesn't contains any value

broken parrot
pearl otter
broken parrot
pearl otter
#

0

#

every time

#

but it says 34 in the UnitController debug.Log

broken parrot
#

you have a yield return null between AddTiles and the debug.log, could it be that the list is getting cleared in that frame?

broken parrot
pearl otter
#

no, the list is cleared in the controller.ClearTiles() function

#
    {
        ClearTiles();
        positionInTilemap = manager.groundTilemap.WorldToCell(transform.position);

        List<List<Vector3Int>> fringes = new List<List<Vector3Int>>();

        for (int k = 0; k <= def.moves; k++)
        {
            if(k == 0)
            {
                fringes.Add(new List<Vector3Int>());
                fringes[0].Add(positionInTilemap);
                continue;
            }
            fringes.Add(new List<Vector3Int>());
            foreach (Vector3Int targetedTile in fringes[k-1])
            {
                for (int dir = 0; dir < 6; dir++)
                {
                    Vector3Int neighbour = CombatTilesHelper.GetOffsetNeighbour(targetedTile, dir);
                    if(manager.groundTilemap.GetTile<HexagonalGroundTile>(neighbour).walkable && !nextMoves.Contains(neighbour))
                    {
                        fringes[k].Add(neighbour);
                        nextMoves.Add(neighbour);
                    }
                }
            }
        }

        foreach(Vector3Int targetedTile in nextMoves)
        {
            manager.groundTilemap.SetTile(targetedTile, CombatTilesHelper.GetTileModel("GreenHexTile"));
            manager.groundTilemap.RefreshTile(targetedTile);
        }
        Debug.Log(nextMoves.Count);
    }
#

this is the AddTiles function in the UnitController script

#
    {
        foreach(UnitController controller in myUnits)
        {
            controller.AddTiles();
            yield return null;
            List<Vector3Int> nextMoves = controller.nextMoves;
            Debug.Log(nextMoves.Count);
            yield return null;
            controller.ClearTiles();
            Vector3Int nextTile = nextMoves[Random.Range(0, nextMoves.Count - 1)];
            controller.nextTile = nextTile;
            controller.Move();
            yield return null;
        }
        yield return null;
        manager.Validate();
        Debug.Log("[Bot] A vous !");
    }
#

and this is where i call it in the AutoEnemy script

broken parrot
#

can you put a breakpoint there to see when it's called

pearl otter
#

the error comes before the ClearTiles, it isn't called at all

broken parrot
#

other than that i don't know

pearl otter
#

I just found out that the tiles are cleared every update