Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Tile Map TileData override flags alternate solution

Discussion in '2D Experimental Preview' started by Jay-Pavlina, Jun 14, 2016.

  1. Jay-Pavlina

    Jay-Pavlina

    Joined:
    Feb 19, 2012
    Posts:
    195
    I think the TileFlags that are set on TileData are a little confusing. I have a solution that is more clear, but I don't know if you have language restrictions that prevent you from doing this. Anyway, in C#, I'd use nullable types to cover two of the overrides.

    Instead of TileFlags.OverrideColor, I'd recommend using Color? and if you want to override it, just set it to a value other than null.

    Same thing for TileFlags.OverrideTransform... I'd recommended using Matrix4x4? and just setting it to something other than null if you want to override it.

    So instead of this:
    Code (CSharp):
    1. public class TileData {
    2.   public Color color;
    3.   public Matrix4x4 transform;
    4.   public int flags;
    5.   // ...
    6. }
    You would have this:
    Code (CSharp):
    1. public class TileData {
    2.   public Color? color;
    3.   public Matrix4x4? transform;
    4.   // no flags ...
    5. }
    I don't have a solution for TileFlags.OverrideSpawnGameObjectRuntimeOnly, but since that relates to the editor only, it seems like it shouldn't be in the game code. Just my thoughts...
     
    Xepherys likes this.
  2. Xepherys

    Xepherys

    Joined:
    Sep 9, 2012
    Posts:
    178
    This would certainly make things more clear. There would have to be a Nullable<T> version of the types, but I don't see any reason that would be impossible to do.
     
  3. Xelnath

    Xelnath

    Joined:
    Jan 31, 2015
    Posts:
    259
    Seconded. I feel like in general, the lack of nullability on Unity properties means that it is very hard to say:

    "I want this to use the default value from code".
     
    Xepherys likes this.