Animated Tile tilemap.gettile problem

I am trying to get the tile information from a ball position, after shot played.
The following code works fine for the none animated tiles but not the animated tiles.

   [SerializeField]
    private Tilemap groundTilemap;

    [SerializeField]
    private string ballLie;

    //XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    public string CheckTile()
    {
        Vector2 ballPos = gameman.GetBallPosition();

        Vector3Int v3int = new Vector3Int(Mathf.RoundToInt(ballPos.x - 0.5f), Mathf.RoundToInt(ballPos.y - 0.5f));
        TileBase currentTile = groundTilemap.GetTile(v3int);
     
        if(currentTile != null)
        {
            //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
            //FAIRWAY TILES
            if (currentTile.name == "fairway1tileset_0" || currentTile.name == "fairway1tileset_1")
            {
                ballLie = "FAIRWAY";
            }
     
        //LIGHTROUGH TILES
            //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

        if (currentTile.name == "LightRoughTileset1_0" || currentTile.name == "LightRoughTileset1_1")
        {
             ballLie = "LIGHT ROUGH";
        }

        //HEAVY ROUGH TILES
            //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

            if (currentTile.name == "HeavyRoughTileset1_0" || currentTile.name == "HeavyRoughTileset1_1")
        {
            ballLie = "HEAVY ROUGH";
        }

        //ANIMATED TILES
        //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
            //WATER TILES
            if (currentTile.name == "wateranimstart1_1" || currentTile.name == "wateranimstart1_2")
        {
             ballLie = "WATER";
        }

      }

            return ballLie;

    }

So for animated tiles it does “not work fine.”

Not super useful. My only suggestion would be, “You should make it work fine then too.”

How to report your problem productively in the Unity3D forums:

http://plbm.com/?p=220

You can edit your post above.

Okay, the point I was making was in the currenttile.name == “watertileset_1” not working as do the the normal tiles, which is to return the balllie.

Well if it’s not equal, print it out and find out what it is!!

You must find a way to get the information you need in order to reason about what the problem is.

What is often happening in these cases is one of the following:

  • the code you think is executing is not actually executing at all
  • the code is executing far EARLIER or LATER than you think
  • the code is executing far LESS OFTEN than you think
  • the code is executing far MORE OFTEN than you think
  • the code is executing on another GameObject than you think it is
  • you’re getting an error or warning and you haven’t noticed it in the console window

To help gain more insight into your problem, I recommend liberally sprinkling Debug.Log() statements through your code to display information in realtime.

Doing this should help you answer these types of questions:

  • is this code even running? which parts are running? how often does it run? what order does it run in?
  • what are the values of the variables involved? Are they initialized? Are the values reasonable?
  • are you meeting ALL the requirements to receive callbacks such as triggers / colliders (review the documentation)

Knowing this information will help you reason about the behavior you are seeing.

You can also put in Debug.Break() to pause the Editor when certain interesting pieces of code run, and then study the scene manually, looking for all the parts, where they are, what scripts are on them, etc.

You could also just display various important quantities in UI Text elements to watch them change as you play the game.

If you are running a mobile device you can also view the console output. Google for how on your particular mobile target.

Another useful approach is to temporarily strip out everything besides what is necessary to prove your issue. This can simplify and isolate compounding effects of other items in your scene or prefab.

Here’s an example of putting in a laser-focused Debug.Log() and how that can save you a TON of time wallowing around speculating what might be going wrong:

https://discussions.unity.com/t/839300/3

Hi, your solution to use more debug statements did work thanks.
I used if(currenttile !- null) debug.log currenttile,name), which were the names of the animated tiles not the names of the tileset as used with the none animated tiles.