Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Editor properties for custom tile

Discussion in '2D' started by GLeBaTi, Feb 25, 2020.

  1. GLeBaTi

    GLeBaTi

    Joined:
    Jan 12, 2013
    Posts:
    47
  2. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,319
    Try inheriting from TileBase. "Tile" might be using a custom Inspector, suppressing the normal inspector showing the float. You could also make your own custom Inspector if you want something fancy.
     
  3. GLeBaTi

    GLeBaTi

    Joined:
    Jan 12, 2013
    Posts:
    47
    It shown if i select tile in "project" window. But this is not shown if i click on tile in "Scene" window.
     
  4. GLeBaTi

    GLeBaTi

    Joined:
    Jan 12, 2013
    Posts:
    47
  5. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,319
    Where you have your wood, each wood references the same Tile. There reason why the GridSelection tool doesn't give you its properties like that is that would imply that you can edit per-tile properties, which you cannot. All wood have the same Speed. In other words, when looking at a particular position, if there's a wood there, you can't adjust the speed for that position, only across all places where there's wood by changing the asset (in project window). So, GridSelection only tells you what Tile asset is at a particular spot. You can then adjust that asset's properties from the Inspector for the asset.
     
    bluny00 and GLeBaTi like this.
  6. GLeBaTi

    GLeBaTi

    Joined:
    Jan 12, 2013
    Posts:
    47
    Thanks for reply! This is helpful :)
     
  7. bluny00

    bluny00

    Joined:
    Feb 18, 2020
    Posts:
    2
    I will slightly divert this thread. I hope that is okay.

    So this part in the example:
    Code (CSharp):
    1.     private bool HasRoadTile(ITilemap tilemap, Vector3Int position)
    2.     {
    3.         return tilemap.GetTile(position) == this;
    4.     }
    works because of the same reason?
    When I was looking into the example I thought this isn't right, that it would only be true when the instance of the RoadTile is at that specific position, and that the correct version for the function would be something like this:
    Code (CSharp):
    1.     private bool HasRoadTile(ITilemap tilemap, Vector3Int position)
    2.     {
    3.         return tilemap.GetTile<RoadTile>(position) != null;
    4.     }
    But it would be also surprising if such a mistake went unnoticed in the documentation for more than two years, so I started to look into the forum.

    But it feels like now I get it, there is only one RoadTile instance which can be present in multiple cells in the Scene, that is why it works with the "== this". Is this correct?
    Is there a case where there would be multiple RoadTile instances in the same Scene?
     
    GLeBaTi likes this.
  8. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,319
    That is correct. "== this" is doing reference comparison. Keep in mind, you could create multiple tile assets of the same road tile script. Then the "==this" is checking whether this instance (i.e. this asset) is the same as that instance at the particular cell.

    Yes, create a RoadTile asset. Then copy and paste it in the Project. Then paint both to the same tilemap. Now you have multiple on the same tilemap.
     
    bluny00 likes this.
  9. Aridez

    Aridez

    Joined:
    Feb 12, 2014
    Posts:
    13
    And in the case that I want an editable property on a per-tile basis how should we go about it? For example, I might set up a tile that can be burned, then once burnt I want to be able to set and check a boolean "isBurnt" and potentially do other actions (such as changing its sprite or burning neighbor tiles among others)
     
    Last edited: Sep 24, 2022
  10. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,319
    Three strategies:
     
    Kurt-Dekker likes this.
  11. Aridez

    Aridez

    Joined:
    Feb 12, 2014
    Posts:
    13
    The problem with #1 would be that the power of using the Tile Palette would be lost, which would be a shame since it speeds up the creation of the maps a ton. For #2 I've seen that Unity offers the GridInformation script, even though it is not supported anymore, but with that solution then we lose the power of using the inspector to quickly edit each tile settings.

    I think it is a lose-lose situation with each solution without a way around
     
  12. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,319
    With #1, it's possible to attach a prefab to a tile. There's even a Prefab Brush in the Tilemap Extras package:
    https://docs.unity3d.com/Packages/com.unity.2d.tilemap.extras@1.5/manual/PrefabBrush.html

    With #2, the overall strategy is to keep a strict separation between the Visual Layer and the Gameplay Layer. The tilemap becomes a visual representation of gameplay data rather than being associated with any tiles themselves. This is more suitable for certain types of games (simulations) than others (pre-designed levels).

    With any solution, you may find you need to build an in-game or editor tool to print information. The GridInformation is never going to be able to print everything you may need, especially if you want lots of custom data. The #1 solution with Prefab/GameObjects can still make use of the Inspector. There's also this free asset which I haven't used but aims to solve this problem.
     
    roberto_sc likes this.