#Hello i m working on a small project and
1 messages · Page 1 of 1 (latest)
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
what does the debug.log in the screenshot print?
the number of Vector3Int in my List
i mean what number does it print
you have a yield return null between AddTiles and the debug.log, could it be that the list is getting cleared in that frame?
can you show that code? either paste site or with back ticks ```
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
you could have something else that calls ClearTiles
can you put a breakpoint there to see when it's called
the error comes before the ClearTiles, it isn't called at all
either nothing is added to nextMoves, or something is removing items from nextMoves, and it looks like nextMoves is being added to
other than that i don't know
I just found out that the tiles are cleared every update