2d-extras icon indicating copy to clipboard operation
2d-extras copied to clipboard

When upgrade how to keep Rule Tile data?

Open MarkHub2019 opened this issue 6 years ago • 10 comments

Hi, I try to use this from 2d-techdemos. It is very cool and helpful. It required For use with Unity 2019.2.0a7 onwards. Now I upgrade unity to 2019.2.10f, since 2019.2.8 or 7. It start to report two type of errors like below: It is reference to Rule Tile and Override Rule Tiles I created. I tried to remove the old package, and down the new package to /asset. The errors gone. But the rule settings lost also lost the reference of RuleTile.cs . How to avoid that? Thanks.

1: NullReferenceException: Object reference not set to an instance of an object UnityEngine.RuleTile.RuleMatches (UnityEngine.RuleTile+TilingRule rule, UnityEngine.Tilemaps.TileBase[]& neighboringTiles, System.Int32 angle) (at Assets/2d-techdemos-master/Assets/Tilemap/Rule Tiles/Scripts/RuleTile.cs:243) UnityEngine.RuleTile.RuleMatches (UnityEngine.RuleTile+TilingRule rule, UnityEngine.Tilemaps.TileBase[]& neighboringTiles, UnityEngine.Matrix4x4& transform) (at Assets/2d-techdemos-master/Assets/Tilemap/Rule Tiles/Scripts/RuleTile.cs:186) UnityEngine.RuleTile.GetTileData (UnityEngine.Vector3Int position, UnityEngine.Tilemaps.ITilemap tilemap, UnityEngine.Tilemaps.TileData& tileData) (at Assets/2d-techdemos-master/Assets/Tilemap/Rule Tiles/Scripts/RuleTile.cs:111)

2: Error running GetTileData for new TileNullReferenceException: Object reference not set to an instance of an object UnityEngine.RuleTile.RuleMatches (UnityEngine.RuleTile+TilingRule rule, UnityEngine.Tilemaps.TileBase[]& neighboringTiles, System.Int32 angle) (at Assets/2d-techdemos-master/Assets/Tilemap/Rule Tiles/Scripts/RuleTile.cs:243) UnityEngine.RuleTile.RuleMatches (UnityEngine.RuleTile+TilingRule rule, UnityEngine.Tilemaps.TileBase[]& neighboringTiles, UnityEngine.Matrix4x4& transform) (at Assets/2d-techdemos-master/Assets/Tilemap/Rule Tiles/Scripts/RuleTile.cs:186) UnityEngine.RuleTile.GetTileData (UnityEngine.Vector3Int position, UnityEngine.Tilemaps.ITilemap tilemap, UnityEngine.Tilemaps.TileData& tileData) (at Assets/2d-techdemos-master/Assets/Tilemap/Rule Tiles/Scripts/RuleTile.cs:111)

MarkHub2019 avatar Oct 29 '19 02:10 MarkHub2019

Your situation may be due to the existence of two 2d-extras, the script guid repetition caused the script link to be lost. From your log you can see that one of the 2d-extras is located at Assets/2d-techdemos-master/Assets/Tilemap/, and another 2d-extras may be installed by the PackageManager. I suggest you delete Assets/2d-techdemos-master and re-download, because the current version of 2d-techdemos does not contain 2d-extras, you should be able to upgrade smoothly.

johnsoncodehk avatar Oct 29 '19 14:10 johnsoncodehk

Thanks Johnsoncodehk, Yes I found it located at Assets/2d-techdemos-master/Assets/Tilemap/. But do not find another one installed by PackageManager. I do not have a folder like this Packages/com.unity.2d.tilemap.extras My rule tile was located at Assets/TilePalette/

Now I follow your advice, first delete Assets/2d-techdemos-master. Then download Unity-Technologies/2d-extras, add it into my project in the folder Packages/com.unity.2d.tilemap.extras. Yes, no error happens time time when I open unity. And I folder called Tilemap Extras appeared in Packages. But all my created rule tiles and ovrride rule tiles lost data, the scriptObject is there and said, The associated script can not be loaded. Please fix any compile errors and assign a valid script. If I drop the ruleTile.cs into it, the settings can not back too.

MarkHub2019 avatar Oct 30 '19 03:10 MarkHub2019

PackageManager resources is in Library/PackageCache/, not in Packages/. Please delete the first one if both folders exist.

  • Packages/com.unity.2d.tilemap.extras
  • Library/PackageCache/com.unity.2d.tilemap.extras@...

johnsoncodehk avatar Oct 30 '19 04:10 johnsoncodehk

This may be tricky to resolve as several issues may cause this:

  • The associated script can not be loaded. Please fix any compile errors and assign a valid script. In the console window, are there any compilation errors logged there? For the 2D extras to work, all compilation errors need to be fixed. If you can share the compilation errors here, we help you out with them. A change in Unity 2019.2 would be the movement of TilemapEditor code to a package and a namespace change to UnityEditor.Tilemaps, which would affect old 2d-Extras code.

  • As johnsoncodehk mentioned, it is possible that there are more than one RuleTile or RuleOverrideTile scripts which conflict against each other. If possible, could you check if there are duplicates and remove them?

  • The reference to the RuleTile script on your RuleTile asset could be wrong when upgrading the 2d-extras, especially if you previously added it to your Assets folder. If you share the text representation of your RuleTile asset (For example, open your RuleTile asset in Notepad or a Text Editor, if your project is serialized in Text), it is possible to check if that is the case (Specifically, the linem_Script: {fileID: 11500000, guid: 9d1514134bc4fbd41bb739b1b9a49231, type: 3}) .

ChuanXin-Unity avatar Oct 30 '19 06:10 ChuanXin-Unity

I download the new package, 2d techdemos-master. And open it in a new project. No errors. It works well. I can see the folder exist. Library/PackageCache/com.unity.2d.tilemap.extras@...

Then I checked my own project (With Assets/2d-techdemos-master download a few months ago). No Packages/com.unity.2d.tilemap.extras No Library/PackageCache/com.unity.2d.tilemap.extras@... Ignore the errors, I can still use rule tiles and override rule tiles to draw.

MarkHub2019 avatar Oct 30 '19 08:10 MarkHub2019

I searched in Assets, there is only one RuleTile there. I found the asset there, and open it in Notedpad, it is too long,part of it like this,: %YAML 1.1 %TAG !u! tag:unity3d.com,2011: --- !u!114 &11400000 MonoBehaviour: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 0} m_Enabled: 1 m_EditorHideFlags: 0 m_Script: {fileID: 11500000, guid: d746e0082aaaaf0458b2b02bb4d45a47, type: 3} m_Name: InnerWallTopRuleTile m_EditorClassIdentifier: m_DefaultSprite: {fileID: 21300002, guid: 2315490ef1abc7045a78b222f20372e5, type: 3} m_DefaultGameObject: {fileID: 0} m_DefaultColliderType: 2 m_TilingRules:

  • m_Neighbors: 0000000002000000000000000200000001000000000000000100000000000000 m_Sprites:
    • {fileID: 21300000, guid: 2315490ef1abc7045a78b222f20372e5, type: 3} m_GameObject: {fileID: 0} m_AnimationSpeed: 1 m_PerlinScale: 0.5 m_RuleTransform: 0 m_Output: 0 m_ColliderType: 2 m_RandomTransform: 0
  • m_Neighbors: 0000000002000000000000000100000001000000000000000100000000000000 m_Sprites:
    • {fileID: 21300002, guid: 2315490ef1abc7045a78b222f20372e5, type: 3}
    • {fileID: 21300004, guid: 2315490ef1abc7045a78b222f20372e5, type: 3}
    • {fileID: 21300006, guid: 2315490ef1abc7045a78b222f20372e5, type: 3}
    • {fileID: 21300008, guid: 2315490ef1abc7045a78b222f20372e5, type: 3}
    • {fileID: 21300038, guid: 2315490ef1abc7045a78b222f20372e5, type: 3}
    • {fileID: 21300040, guid: 2315490ef1abc7045a78b222f20372e5, type: 3}
    • {fileID: 21300042, guid: 2315490ef1abc7045a78b222f20372e5, type: 3}
    • {fileID: 21300044, guid: 2315490ef1abc7045a78b222f20372e5, type: 3} m_GameObject: {fileID: 0}

MarkHub2019 avatar Oct 30 '19 08:10 MarkHub2019

The error code reference this line: tile = (tile as RuleOverrideTile).m_RuntimeTile.m_Self; In this function protected bool RuleMatches(TilingRule rule, ref TileBase[] neighboringTiles, int angle) { for (int i = 0; i < neighborCount; ++i) { int index = GetRotatedIndex(i, angle); TileBase tile = neighboringTiles[index]; if (tile is RuleOverrideTile) tile = (tile as RuleOverrideTile).m_RuntimeTile.m_Self; if (!RuleMatch(rule.m_Neighbors[i], tile)) { return false; } } return true; }

MarkHub2019 avatar Oct 30 '19 08:10 MarkHub2019

Due to limited information, it may be difficult to help you. I recommend that you copy all the assets to your new project of 2d-techdemos-master, but don't copy the 2d-extras script. This should solve the code error problem. If the script reference is still missing, you will need to manually change the guid of this line.

m_Script: {fileID: 11500000, guid: d746e0082aaaaf0458b2b02bb4d45a47, type: 3}

For the correct guid, please see RuleTile.cs.meta or the corresponding tile type file in the Library/PackageCache/com.unity.2d.tilemap.extras@....

johnsoncodehk avatar Oct 30 '19 11:10 johnsoncodehk

I Upgraded unity to 2019.2.11f1, First time open unity. It have 8 warnings. Does this help to find out the bugs? 1. Timestamps (6232) and assets (6231) maps out of sync - repairing... 2. The AssetDatabase contains a timestamp for 'C:/Program Files/Unity/Hub/Editor/2019.2.10f1/Editor/Data/UnityExtensions/Unity/UnityVR/Editor/UnityEditor.VR.dll', but no mapped GUID. This timestamp will be removed from the database. 3-8 Identifier uniqueness violation: 'Name:minebot_front_upperleg, Type:Mesh'. Multiple Objects with the same name/type are generated by this Importer. There is no guarantee that subsequent imports of this asset will properly re-link to these targets.

MarkHub2019 avatar Nov 02 '19 01:11 MarkHub2019

Sorry, I am unable to tell from the logs.

If you do not mind, could you file a bug report using the Unity Bug Reporter with your project and post the case number here? This would allow me to take a look directly at the project and help you out!

ChuanXin-Unity avatar Nov 06 '19 09:11 ChuanXin-Unity