Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by thristram · May 06, 2019 at 04:58 AM · editortilemapscriptableobject

Unity 2019.1.1f1 Runtime Scriptable Tilebase Not loading problem (Works on Unity Editor)

I was creating a Scriptable Tilebase and place it on the isometric tilemap (code below). When placing on the tilmap, everything works fine, but after building, all smart tlies start to disappear. Log says the smart tile object is null. The project was recently upgraded from 2018.3 and everything seems fine on 2018.3. Please help.

//Unity Editor alt text

//Build alt text

 using System.Collections;
 using System.Collections.Generic;
 using System.Linq;
 
 #if UNITY_EDITOR
 using UnityEditor;
 #endif
 
 using UnityEngine;
 
 namespace UnityEngine.Tilemaps{
 
     [CreateAssetMenu]
     public class IsometricSmartTile : Tile{
         [SerializeField] public isometricSprite[] m_Sprites;
 
         [SerializeField] public int m_layerIndex = 0;
 
         public override void RefreshTile(Vector3Int location, ITilemap tileMap){
             for (int yd = -1; yd <= 1; yd++)
             for (int xd = -1; xd <= 1; xd++){
                 Vector3Int position = new Vector3Int(location.x + xd, location.y + yd, location.z);
                 if (TileValue(tileMap, position))
                     tileMap.RefreshTile(position);
             }
         }
 
         public override void GetTileData(Vector3Int location, ITilemap tileMap, ref TileData tileData){
             UpdateTile(location, tileMap, ref tileData);
         }
 
         private void UpdateTile(Vector3Int location, ITilemap tileMap, ref TileData tileData){
             tileData.transform = Matrix4x4.identity;
             tileData.color = Color.white;
 
             int mask = TileValue(tileMap, location + new Vector3Int(0, 1, 0)) ? 1 : 0;
             mask += TileValue(tileMap, location + new Vector3Int(1, 1, 0)) ? 2 : 0;
             mask += TileValue(tileMap, location + new Vector3Int(1, 0, 0)) ? 4 : 0;
             mask += TileValue(tileMap, location + new Vector3Int(1, -1, 0)) ? 8 : 0;
             mask += TileValue(tileMap, location + new Vector3Int(0, -1, 0)) ? 16 : 0;
             mask += TileValue(tileMap, location + new Vector3Int(-1, -1, 0)) ? 32 : 0;
             mask += TileValue(tileMap, location + new Vector3Int(-1, 0, 0)) ? 64 : 0;
             mask += TileValue(tileMap, location + new Vector3Int(-1, 1, 0)) ? 128 : 0;
 
             byte original = (byte) mask;
             if ((original | 254) < 255){
                 mask = mask & 125;
             }
 
             if ((original | 251) < 255){
                 mask = mask & 245;
             }
 
             if ((original | 239) < 255){
                 mask = mask & 215;
             }
 
             if ((original | 191) < 255){
                 mask = mask & 95;
             }
 
             int index = GetIndex((byte) mask);
             if (index >= 0 && index < m_Sprites.Length && TileValue(tileMap, location)){
                 tileData.sprite = m_Sprites[index].getSprite(GetTransform((byte) mask));
                 tileData.color = Color.white;
                 tileData.flags = TileFlags.LockTransform | TileFlags.LockColor;
                 tileData.colliderType = Tile.ColliderType.Sprite;
             }
         }
 
         private bool TileValue(ITilemap tileMap, Vector3Int position){
             TileBase tile = tileMap.GetTile(position);
 
             IsometricSmartTile SmartTile = tileMap.GetTile<IsometricSmartTile>(position);
 
             if (SmartTile != null){
                 if (m_layerIndex != SmartTile.m_layerIndex)
                     tile = null;
             }
 
             return (tile != null && tile == this);
         }
 
         private int GetIndex(byte mask){
             switch (mask){
                 case 0: return 0;
                 case 1:
                 case 4:
                 case 16:
                 case 64: return 1;
                 case 5:
                 case 20:
                 case 80:
                 case 65: return 2;
                 case 7:
                 case 28:
                 case 112:
                 case 193: return 3;
                 case 17:
                 case 68: return 4;
                 case 21:
                 case 84:
                 case 81:
                 case 69: return 5;
                 case 23:
                 case 92:
                 case 113:
                 case 197: return 6;
                 case 29:
                 case 116:
                 case 209:
                 case 71: return 7;
                 case 31:
                 case 124:
                 case 241:
                 case 199: return 8;
                 case 85: return 9;
                 case 87:
                 case 93:
                 case 117:
                 case 213: return 10;
                 case 95:
                 case 125:
                 case 245:
                 case 215: return 11;
                 case 119:
                 case 221: return 12;
                 case 127:
                 case 253:
                 case 247:
                 case 223: return 13;
                 case 255: return 14;
             }
 
             return -1;
         }
 
         private int GetTransform(byte mask){
             switch (mask){
                 case 4:
                 case 20:
                 case 28:
                 case 68:
                 case 84:
                 case 92:
                 case 116:
                 case 124:
                 case 93:
                 case 125:
                 case 221:
                 case 253:
                     return 1;
                 case 16:
                 case 80:
                 case 112:
                 case 81:
                 case 113:
                 case 209:
                 case 241:
                 case 117:
                 case 245:
                 case 247:
                     return 2;
                 case 64:
                 case 65:
                 case 193:
                 case 69:
                 case 197:
                 case 71:
                 case 199:
                 case 213:
                 case 215:
                 case 223:
                     return 3;
             }
             return 0;
         }
 
         [System.Serializable]
         public class isometricSprite{
             public Sprite sprite_1;
             public Sprite sprite_2;
             public Sprite sprite_3;
             public Sprite sprite_4;
 
             public Sprite getSprite(int number){
                 switch (number){
                     case 1: return sprite_2;
                     case 2: return sprite_3;
                     case 3: return sprite_4;
                     default: return sprite_1;
                 }
             }
 
             public void setSprite(int number, Sprite sprite){
                 switch (number){
                     case 1:
                         sprite_2 = sprite;
                         break;
                     case 2:
                         sprite_3 = sprite;
                         break;
                     case 3:
                         sprite_4 = sprite;
                         break;
                     default:
                         sprite_1 = sprite;
                         break;
                 }
             }
         }
 
 
 
 #if UNITY_EDITOR
         [MenuItem("Assets/Create/Isometric Smart Tile")]
         public static void CreateIsometricSmartTile()
         {
             string path = EditorUtility.SaveFilePanelInProject("Save Isometric Smart Tile", "New Isometric Smart Tile", "asset", "Save Isometric Smart Tile", "Assets");
 
             if (path == "")
                 return;
 
             AssetDatabase.CreateAsset(ScriptableObject.CreateInstance<IsometricSmartTile>(), path);
         }
 #endif
     }
 
 #if UNITY_EDITOR
     [CustomEditor(typeof(IsometricSmartTile))]
     public class IsometricSmartTileEditor : Editor
     {
         private IsometricSmartTile tile { get { return (target as IsometricSmartTile); } }
         private string[] labelFields = new string[] {"Filled", "Three Sides", "Two Sides and One Corner", "Two Adjacent Sides", "Two Opposite Sides", "One Side and Two Corners", "One Side and One Lower Corner", "One Side and One Upper Corner", "One Side","Four Corners","Three Corners","Two Adjacent Corners","Two Opposite Corners","One Corner","Empty"};
         public void OnEnable(){
         
             if (tile.m_Sprites == null )
             {
                 tile.m_Sprites = new IsometricSmartTile.isometricSprite[labelFields.Length];
                 Debug.Log("Overriding New Tiles");
                 for (int i = 0; i < tile.m_Sprites.Length; i++){
                     tile.m_Sprites[i] = new IsometricSmartTile.isometricSprite();
                 }
                 EditorUtility.SetDirty(tile);
             }
         }
 
 
         public override void OnInspectorGUI(){
             EditorGUILayout.LabelField("Place sprites shown based on the contents of the sprite.");
             EditorGUILayout.Space();
 
             float oldLabelWidth = EditorGUIUtility.labelWidth;
             EditorGUIUtility.labelWidth = 210;
 
             EditorGUI.BeginChangeCheck();
 
             tile.m_layerIndex = EditorGUILayout.IntField("Layer", tile.m_layerIndex);
         
 
             for (int a = 0; a < labelFields.Length; a++){
                 EditorGUILayout.LabelField(labelFields[a]);
                 EditorGUILayout.Space();
             
                 for (int i = 0; i < 4; i++){
 //                
                     Sprite spriteToSet = (Sprite) EditorGUILayout.ObjectField(labelFields[a] + " " + i.ToString(),
                         tile.m_Sprites[a].getSprite(i) , typeof(Sprite), false, null);
                     tile.m_Sprites[a].setSprite(i, spriteToSet);
                 }
             
             }
 
             if (EditorGUI.EndChangeCheck())
                 EditorUtility.SetDirty(tile);
 
             EditorGUIUtility.labelWidth = oldLabelWidth;
         }
     }
 #endif
  
 }


,I was creating a Scriptable Tilebase and place it on the isometric tilemap (code below). When placing on the tilmap, everything works fine, but after building, all smart tlies start to disappear. Log says the smart tile object is null. The project was recently upgraded from 2018.3 and everything seems fine. Please help.

//Unity Editor alt text

//Build alt text

 using System.Collections;
 using System.Collections.Generic;
 using System.Linq;
 
 #if UNITY_EDITOR
 using UnityEditor;
 #endif
 
 using UnityEngine;
 
 namespace UnityEngine.Tilemaps{
 
     [CreateAssetMenu]
     public class IsometricSmartTile : Tile{
         [SerializeField] public isometricSprite[] m_Sprites;
 
         [SerializeField] public int m_layerIndex = 0;
 
         public override void RefreshTile(Vector3Int location, ITilemap tileMap){
             for (int yd = -1; yd <= 1; yd++)
             for (int xd = -1; xd <= 1; xd++){
                 Vector3Int position = new Vector3Int(location.x + xd, location.y + yd, location.z);
                 if (TileValue(tileMap, position))
                     tileMap.RefreshTile(position);
             }
         }
 
         public override void GetTileData(Vector3Int location, ITilemap tileMap, ref TileData tileData){
             UpdateTile(location, tileMap, ref tileData);
         }
 
         private void UpdateTile(Vector3Int location, ITilemap tileMap, ref TileData tileData){
             tileData.transform = Matrix4x4.identity;
             tileData.color = Color.white;
 
             int mask = TileValue(tileMap, location + new Vector3Int(0, 1, 0)) ? 1 : 0;
             mask += TileValue(tileMap, location + new Vector3Int(1, 1, 0)) ? 2 : 0;
             mask += TileValue(tileMap, location + new Vector3Int(1, 0, 0)) ? 4 : 0;
             mask += TileValue(tileMap, location + new Vector3Int(1, -1, 0)) ? 8 : 0;
             mask += TileValue(tileMap, location + new Vector3Int(0, -1, 0)) ? 16 : 0;
             mask += TileValue(tileMap, location + new Vector3Int(-1, -1, 0)) ? 32 : 0;
             mask += TileValue(tileMap, location + new Vector3Int(-1, 0, 0)) ? 64 : 0;
             mask += TileValue(tileMap, location + new Vector3Int(-1, 1, 0)) ? 128 : 0;
 
             byte original = (byte) mask;
             if ((original | 254) < 255){
                 mask = mask & 125;
             }
 
             if ((original | 251) < 255){
                 mask = mask & 245;
             }
 
             if ((original | 239) < 255){
                 mask = mask & 215;
             }
 
             if ((original | 191) < 255){
                 mask = mask & 95;
             }
 
             int index = GetIndex((byte) mask);
             if (index >= 0 && index < m_Sprites.Length && TileValue(tileMap, location)){
                 tileData.sprite = m_Sprites[index].getSprite(GetTransform((byte) mask));
                 tileData.color = Color.white;
                 tileData.flags = TileFlags.LockTransform | TileFlags.LockColor;
                 tileData.colliderType = Tile.ColliderType.Sprite;
             }
         }
 
         private bool TileValue(ITilemap tileMap, Vector3Int position){
             TileBase tile = tileMap.GetTile(position);
 
             IsometricSmartTile SmartTile = tileMap.GetTile<IsometricSmartTile>(position);
 
             if (SmartTile != null){
                 if (m_layerIndex != SmartTile.m_layerIndex)
                     tile = null;
             }
 
             return (tile != null && tile == this);
         }
 
         private int GetIndex(byte mask){
             switch (mask){
                 case 0: return 0;
                 case 1:
                 case 4:
                 case 16:
                 case 64: return 1;
                 case 5:
                 case 20:
                 case 80:
                 case 65: return 2;
                 case 7:
                 case 28:
                 case 112:
                 case 193: return 3;
                 case 17:
                 case 68: return 4;
                 case 21:
                 case 84:
                 case 81:
                 case 69: return 5;
                 case 23:
                 case 92:
                 case 113:
                 case 197: return 6;
                 case 29:
                 case 116:
                 case 209:
                 case 71: return 7;
                 case 31:
                 case 124:
                 case 241:
                 case 199: return 8;
                 case 85: return 9;
                 case 87:
                 case 93:
                 case 117:
                 case 213: return 10;
                 case 95:
                 case 125:
                 case 245:
                 case 215: return 11;
                 case 119:
                 case 221: return 12;
                 case 127:
                 case 253:
                 case 247:
                 case 223: return 13;
                 case 255: return 14;
             }
 
             return -1;
         }
 
         private int GetTransform(byte mask){
             switch (mask){
                 case 4:
                 case 20:
                 case 28:
                 case 68:
                 case 84:
                 case 92:
                 case 116:
                 case 124:
                 case 93:
                 case 125:
                 case 221:
                 case 253:
                     return 1;
                 case 16:
                 case 80:
                 case 112:
                 case 81:
                 case 113:
                 case 209:
                 case 241:
                 case 117:
                 case 245:
                 case 247:
                     return 2;
                 case 64:
                 case 65:
                 case 193:
                 case 69:
                 case 197:
                 case 71:
                 case 199:
                 case 213:
                 case 215:
                 case 223:
                     return 3;
             }
             return 0;
         }
 
         [System.Serializable]
         public class isometricSprite{
             public Sprite sprite_1;
             public Sprite sprite_2;
             public Sprite sprite_3;
             public Sprite sprite_4;
 
             public Sprite getSprite(int number){
                 switch (number){
                     case 1: return sprite_2;
                     case 2: return sprite_3;
                     case 3: return sprite_4;
                     default: return sprite_1;
                 }
             }
 
             public void setSprite(int number, Sprite sprite){
                 switch (number){
                     case 1:
                         sprite_2 = sprite;
                         break;
                     case 2:
                         sprite_3 = sprite;
                         break;
                     case 3:
                         sprite_4 = sprite;
                         break;
                     default:
                         sprite_1 = sprite;
                         break;
                 }
             }
         }
 
 
 
 #if UNITY_EDITOR
         [MenuItem("Assets/Create/Isometric Smart Tile")]
         public static void CreateIsometricSmartTile()
         {
             string path = EditorUtility.SaveFilePanelInProject("Save Isometric Smart Tile", "New Isometric Smart Tile", "asset", "Save Isometric Smart Tile", "Assets");
 
             if (path == "")
                 return;
 
             AssetDatabase.CreateAsset(ScriptableObject.CreateInstance<IsometricSmartTile>(), path);
         }
 #endif
     }
 
 #if UNITY_EDITOR
     [CustomEditor(typeof(IsometricSmartTile))]
     public class IsometricSmartTileEditor : Editor
     {
         private IsometricSmartTile tile { get { return (target as IsometricSmartTile); } }
         private string[] labelFields = new string[] {"Filled", "Three Sides", "Two Sides and One Corner", "Two Adjacent Sides", "Two Opposite Sides", "One Side and Two Corners", "One Side and One Lower Corner", "One Side and One Upper Corner", "One Side","Four Corners","Three Corners","Two Adjacent Corners","Two Opposite Corners","One Corner","Empty"};
         public void OnEnable(){
         
             if (tile.m_Sprites == null )
             {
                 tile.m_Sprites = new IsometricSmartTile.isometricSprite[labelFields.Length];
                 Debug.Log("Overriding New Tiles");
                 for (int i = 0; i < tile.m_Sprites.Length; i++){
                     tile.m_Sprites[i] = new IsometricSmartTile.isometricSprite();
                 }
                 EditorUtility.SetDirty(tile);
             }
         }
 
 
         public override void OnInspectorGUI(){
             EditorGUILayout.LabelField("Place sprites shown based on the contents of the sprite.");
             EditorGUILayout.Space();
 
             float oldLabelWidth = EditorGUIUtility.labelWidth;
             EditorGUIUtility.labelWidth = 210;
 
             EditorGUI.BeginChangeCheck();
 
             tile.m_layerIndex = EditorGUILayout.IntField("Layer", tile.m_layerIndex);
         
 
             for (int a = 0; a < labelFields.Length; a++){
                 EditorGUILayout.LabelField(labelFields[a]);
                 EditorGUILayout.Space();
             
                 for (int i = 0; i < 4; i++){
 //                
                     Sprite spriteToSet = (Sprite) EditorGUILayout.ObjectField(labelFields[a] + " " + i.ToString(),
                         tile.m_Sprites[a].getSprite(i) , typeof(Sprite), false, null);
                     tile.m_Sprites[a].setSprite(i, spriteToSet);
                 }
             
             }
 
             if (EditorGUI.EndChangeCheck())
                 EditorUtility.SetDirty(tile);
 
             EditorGUIUtility.labelWidth = oldLabelWidth;
         }
     }
 #endif
  
 }

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
â–¼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

205 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Making Node editor but having problem with passing through non static data to static method 0 Answers

Assets not loading correctly at startup 1 Answer

Crash when reimporting custom assets 0 Answers

How to apply composition to ScriptableObjects 0 Answers

Load JSON Scriptable Object and Prefabs 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges