NavMeshPlus icon indicating copy to clipboard operation
NavMeshPlus copied to clipboard

Ruletiles

Open loaril opened this issue 2 years ago • 7 comments

Would it be possible to get Navigation Modifier Tilemap work with ruletiles?

This is the error I'm getting with ruletiles:

Error NullReferenceException: Object reference not set to an instance of an object UnityEngine.RuleTile.RuleMatches (UnityEngine.RuleTile+TilingRule rule, UnityEngine.Vector3Int position, UnityEngine.Tilemaps.ITilemap tilemap, System.Int32 angle, System.Boolean mirrorX) (at ./Library/PackageCache/[email protected]/Runtime/Tiles/RuleTile/RuleTile.cs:774) UnityEngine.RuleTile.RuleMatches (UnityEngine.RuleTile+TilingRule rule, UnityEngine.Vector3Int position, UnityEngine.Tilemaps.ITilemap tilemap, UnityEngine.Matrix4x4& transform) (at ./Library/PackageCache/[email protected]/Runtime/Tiles/RuleTile/RuleTile.cs:614) UnityEngine.RuleTile.GetTileData (UnityEngine.Vector3Int position, UnityEngine.Tilemaps.ITilemap tilemap, UnityEngine.Tilemaps.TileData& tileData) (at ./Library/PackageCache/[email protected]/Runtime/Tiles/RuleTile/RuleTile.cs:420) NavMeshPlus.Editors.Components.NavMeshModifierTilemapEditor+TileModifierPropertyDrawer.OnGUI (UnityEngine.Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label) (at Assets/NavMeshComponents/Editor/NavMeshModifierTilemapEditor.cs:121) UnityEditor.PropertyDrawer.OnGUISafe (UnityEngine.Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label) (at :0) UnityEditor.PropertyHandler.OnGUI (UnityEngine.Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, System.Boolean includeChildren, UnityEngine.Rect visibleArea) (at :0) UnityEditor.PropertyHandler.OnGUI (UnityEngine.Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, System.Boolean includeChildren) (at :0) UnityEditorInternal.ReorderableList+Defaults.DrawElement (UnityEngine.Rect rect, UnityEditor.SerializedProperty element, System.Object listItem, System.Boolean selected, System.Boolean focused, System.Boolean draggable, System.Boolean editable) (at :0) UnityEditorInternal.ReorderableList.DoListElements (UnityEngine.Rect listRect, UnityEngine.Rect visibleRect) (at :0) UnityEditorInternal.ReorderableList.DoList (UnityEngine.Rect rect, UnityEngine.Rect visibleRect) (at :0) UnityEditorInternal.ReorderableListWrapper.DrawChildren (UnityEngine.Rect listRect, UnityEngine.Rect headerRect, UnityEngine.Rect sizeRect, UnityEngine.Rect visibleRect, UnityEngine.EventType previousEvent) (at :0) UnityEditorInternal.ReorderableListWrapper.Draw (UnityEngine.GUIContent label, UnityEngine.Rect r, UnityEngine.Rect visibleArea, System.String tooltip, System.Boolean includeChildren) (at :0) UnityEditor.PropertyHandler.OnGUI (UnityEngine.Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, System.Boolean includeChildren, UnityEngine.Rect visibleArea) (at :0) UnityEditor.PropertyHandler.OnGUI (UnityEngine.Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, System.Boolean includeChildren) (at :0) UnityEditor.PropertyHandler.OnGUILayout (UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, System.Boolean includeChildren, UnityEngine.GUILayoutOption[] options) (at :0) UnityEditor.EditorGUILayout.PropertyField (UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, System.Boolean includeChildren, UnityEngine.GUILayoutOption[] options) (at :0) UnityEditor.EditorGUILayout.PropertyField (UnityEditor.SerializedProperty property, UnityEngine.GUILayoutOption[] options) (at :0) NavMeshPlus.Editors.Components.NavMeshModifierTilemapEditor.OnInspectorGUI () (at Assets/NavMeshComponents/Editor/NavMeshModifierTilemapEditor.cs:33) UnityEditor.UIElements.InspectorElement+c__DisplayClass72_0.b__0 () (at :0) UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)

loaril avatar Oct 01 '23 19:10 loaril

Investigation needed.

NavMeshModifierTilemapEditor is not documented. This component still under integration into extensions system.

h8man avatar Oct 02 '23 08:10 h8man

Hello, I also encountered this issue. I solved it by making a custom tile class MyRuleTile that extends RuleTile and handles the scenario in which the tilemap is null:

public class MyRuleTile : RuleTile
{
    public override void GetTileData(Vector3Int position, ITilemap tilemap, ref TileData tileData)
    {
        if (tilemap == null)
        {
            tileData = new TileData();
            tileData.sprite = m_DefaultSprite;
            tileData.colliderType = m_DefaultColliderType;
            tileData.gameObject = m_DefaultGameObject;
        }
        else
        {
            base.GetTileData(position, tilemap, ref tileData);
        }
    }
}

snarlynarwhal avatar Jan 14 '24 18:01 snarlynarwhal

Thx,

I was investigating this issue, seems bug in Unity's package. But I maybe Ill find workaround.

h8man avatar Jan 15 '24 12:01 h8man

here the null parameter is passed as ITilemap to the method.

Quick fix: in method TileModifierPropertyDrawer.OnGUI

`

                //...
                //Code above
                //...
                
                EditorGUI.PropertyField(tileRect, tileProperty);
                TileBase tileBase = tileProperty.objectReferenceValue as TileBase;
                TileData tileData = new TileData();
                Texture TextureToDraw = null;
                if (tileBase is RuleTile)
                {
                    TextureToDraw = EditorGUIUtility.IconContent("console.erroricon.sml").image;
                }
                else
                {
                    tileBase?.GetTileData(Vector3Int.zero, null, ref tileData);
                    TextureToDraw = tileData.sprite.texture;
                }
                
                if (TextureToDraw)
                {
                    EditorGUI.DrawPreviewTexture(previewRect, TextureToDraw, null, ScaleMode.ScaleToFit, 0);
                }
                
                //...
                //Code below
                //...

`

Also should fix asmdef. Снимок экрана 2024-04-19 в 12 57 10

And will look like this Снимок экрана 2024-04-19 в 12 57 50

FoolishEL avatar Apr 19 '24 05:04 FoolishEL

@FoolishEL can you make Merge Request?

h8man avatar May 12 '24 13:05 h8man

@h8man Here you are. https://github.com/h8man/NavMeshPlus/pull/196 I slightly changed how I got around this point, since here it should be taken into account that not everyone installs Tilemap Extras. And I don’t think it’s a good idea to add automatic transfer of definitions to this case.

FoolishEL avatar May 12 '24 17:05 FoolishEL

Снимок экрана 2024-05-13 в 01 03 05

will work with all types except those that do not have a preview method defined in the custom inspector like here

FoolishEL avatar May 12 '24 18:05 FoolishEL

Great job!

h8man avatar May 12 '24 19:05 h8man