2D Toolkit Forum
2D Toolkit => Support => Topic started by: r0l3k on February 05, 2015, 04:08:34 pm
-
Hi,
Suddenly I started getting this error. (possibly after a collider update to one of the prefabs).
NullReferenceException
tk2dRuntime.TileMap.BuilderUtil.HideTileMapPrefabs (.tk2dTileMap tileMap) (at Assets/TK2DROOT/tk2dTileMap/Code/tk2dTileMapBuilderUtil.cs:280)
tk2dTileMap.ClearSpawnedInstances () (at Assets/TK2DROOT/tk2dTileMap/Code/tk2dTileMap.cs:225)
tk2dTileMap.Build (BuildFlags buildFlags) (at Assets/TK2DROOT/tk2dTileMap/Code/tk2dTileMap.cs:304)
tk2dTileMap.EndEditMode () (at Assets/TK2DROOT/tk2dTileMap/Code/tk2dTileMap.cs:526)
tk2dTileMap.Awake () (at Assets/TK2DROOT/tk2dTileMap/Code/tk2dTileMap.cs:117)
UnityEditor.DockArea:OnGUI()
After debugging the code
for (int i = 0; i < instListCount; ++i) {
int x, y, layerIdx;
GameObject instance;
tileMap.GetTilePrefabsListItem(i, out x, out y, out layerIdx, out instance);
// Is it already IN the list for some reason?
if (!instExists) {
int tileId = (x >= 0 && x < tileMap.width && y >= 0 && y < tileMap.height) ? tileMap.GetTile(x, y, layerIdx) : -1;
if (tileId >= 0 && tileId < prefabs.Length && prefabs[tileId] != null) {
instExists = true;
}
}
if (instExists) {
tileX.Add(x);
tileY.Add(y);
tileLayer.Add(layerIdx);
tileInst.Add(instance);
tk2dUtil.SetTransformParent(instance.transform, tileMap.PrefabsRoot.transform);
}
}
in this line: tk2dUtil.SetTransformParent(instance.transform, tileMap.PrefabsRoot.transform);
instance is null.
How to find a broken tile ?
-
I think add if (instExists && instance != null), that should get you past the error and let you fix it in the next commit?
This could happen if the object was deleted in the cached instance list while in edit mode...
-
Thanks.
-
I have a similar problem where TilemapPrefabInstances sometimes are null:
I use a scene for each level. There's one TileMap per scene. All TileMaps are using the same SpriteCollection, tileMapData and tileMapEditorData, and they are all drawn the same way, with the same 4 prefabs placed onto the map.
From code I get to the prefab instance like so:
var tilemapPrefabInstance = CurrentTileMap.TilePrefabsList.Single(i => i.instance.tag == "TagOfTheGameObject");
But in some scenes the TilemapPrefabInstanc.instance suddently is null. I have no idea when and why this happens.
I've tried editing and committing, unlinking the TileMap Render Data, and the advice mentioned here, but nothing helps. It's like, when the error appear, there's no way of getting rid of it again.
Any advice, what I could try next? ???
-
Can you get me a repro when its broken?