Search Unity

Someone can help me I stuck on this for weeks now

Discussion in 'Scripting' started by LazyGhost15, May 25, 2023.

  1. LazyGhost15

    LazyGhost15

    Joined:
    Feb 12, 2022
    Posts:
    120
    I made a horizontal grid (a grid which is xzy instead of xyz) and when I try to get info on a tile using Vector3int if the tile z axis isn't equal to 0 it says the tile is null. I put the tiles manually and I know for a fact, there are tiles in other z values other than 0 but it does recognize all the tiles on the x-axis so the problem has to be in the z-axis but I checked my code several times with different scenes changing the sprite of the tiles and nothing works. I even asked my teacher about it (He isn't teaching me anymore) and he hasn't found the problem when I asked the forum no one really gave me a solution or and bearly commented on the question.
    this is the code and yes I checked the grid the tiles the rotation the scale and every value I thought about:
    Code (CSharp):
    1. for(int x = 0; x < rows; x++)
    2.         {
    3.             for(int z = 1; z < cols; z++)
    4.             {
    5.                 if(tilemap.GetSprite(new Vector3Int(x, 0 , z)) != null)
    6.                 {
    7.                     Sprite sprite = tilemap.GetSprite(new Vector3Int(x , 0 , z));
    8.                     print(x+ " , " + z + " " + sprite.name);
    9.                 }
    10.                 else if(tilemap.GetSprite(new Vector3Int(x, 0, z)) == null)
    11.                 {
    12.                     print(x + " , " + z + " null");
    13.                 }
    14.             }
    15.         }
    can someone please find a solution?
     
  2. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    2,070
    But tiles are ok if you set "z" as 0 and use y instead ?
     
  3. kdgalla

    kdgalla

    Joined:
    Mar 15, 2013
    Posts:
    4,627
    Where are you getting rows and cols? Why are you not using tileMap.Size? Are you actually getting a console output for every cell?
     
  4. LazyGhost15

    LazyGhost15

    Joined:
    Feb 12, 2022
    Posts:
    120
    If y is 0 and z is 0 then everything works. ofc because the grid is horizontal different y shouldn't work but different z should.
     
  5. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,674
    NOTE This is yet another duplicate post of the same unresolved problem.

    Follow OP's history: Rivers of digital ink await you for backstory.
     
  6. LazyGhost15

    LazyGhost15

    Joined:
    Feb 12, 2022
    Posts:
    120
    rows and cols are ints I put manually in the script. I'm not sure what tileMap.size is but I am getting output for each tile and only the tiles in z = 0 give me the sprite I ask it for
     
  7. LazyGhost15

    LazyGhost15

    Joined:
    Feb 12, 2022
    Posts:
    120
    I posted about this before but after no one found an answer I made now another post where I specify more about the problem but when I searched for a tutorial or question about this I couldn't find anything. (I remember you did answer but with another question)
     
  8. kdgalla

    kdgalla

    Joined:
    Mar 15, 2013
    Posts:
    4,627
    I assume that tileMap is of type Tilemap from Unity's tile map package, although you didn't actually specify what it is.

    If that's the case then I would suggest to Debug.Log as many informational properties and methods as you can like tileMap.GetUsedTilesCount and tileMap.size that to make sure the values are what you expect. It could give you a clue about what's going on.
     
    mopthrow likes this.
  9. LazyGhost15

    LazyGhost15

    Joined:
    Feb 12, 2022
    Posts:
    120
    I use a rectangle tile map in this project. I got the position properties from the tiles and whether they were null or not. I didn't know I can get the tilemap size using this function.
     
  10. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,128
    You might think that this makes sense but it doesn't. You're just annoying people trying to assist you by dividing info on the problem across multiple threads, and you're annoying the moderators who have asked you not to do that.
     
  11. AngryProgrammer

    AngryProgrammer

    Joined:
    Jun 4, 2019
    Posts:
    490
    Just print Tilemap.size and post the result. Anything higher than 0 in the y-axis will mean you have done your Tilemap wrong (or not like you wanted to).
     
  12. LazyGhost15

    LazyGhost15

    Joined:
    Feb 12, 2022
    Posts:
    120
    I did that and the results were that z size is 1 and y size is 200. Idk why it didn't work before but I replaced it and it's working!
     
    AngryProgrammer likes this.
  13. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    9,051
    DO NOT MAKE MULTIPLE THREADS ON THE SAME TOPIC. You have been told this before, since you ignored that you have now been given a formal warning. If it happens again, you could lose your ability to participate in these forums. Our rules are very simple and easy to follow, and several people have been very helpful in trying to solve your problem. Please do not be rude and disrespect them by making them pry the basic information out of you. All the other threads are closed. Do not make more on this topic, I cannot be any clearer.
     
    Nad_B and Ryiah like this.