Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ruletiles #168

Open
loaril opened this issue Oct 1, 2023 · 8 comments
Open

Ruletiles #168

loaril opened this issue Oct 1, 2023 · 8 comments

Comments

@loaril
Copy link

loaril commented Oct 1, 2023

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/com.unity.2d.tilemap.extras@3.1.1/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/com.unity.2d.tilemap.extras@3.1.1/Runtime/Tiles/RuleTile/RuleTile.cs:614) UnityEngine.RuleTile.GetTileData (UnityEngine.Vector3Int position, UnityEngine.Tilemaps.ITilemap tilemap, UnityEngine.Tilemaps.TileData& tileData) (at ./Library/PackageCache/com.unity.2d.tilemap.extras@3.1.1/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 <35c0e5f206594d2fa707969117964d70>:0) UnityEditor.PropertyHandler.OnGUI (UnityEngine.Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, System.Boolean includeChildren, UnityEngine.Rect visibleArea) (at <35c0e5f206594d2fa707969117964d70>:0) UnityEditor.PropertyHandler.OnGUI (UnityEngine.Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, System.Boolean includeChildren) (at <35c0e5f206594d2fa707969117964d70>: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 <35c0e5f206594d2fa707969117964d70>:0) UnityEditorInternal.ReorderableList.DoListElements (UnityEngine.Rect listRect, UnityEngine.Rect visibleRect) (at <35c0e5f206594d2fa707969117964d70>:0) UnityEditorInternal.ReorderableList.DoList (UnityEngine.Rect rect, UnityEngine.Rect visibleRect) (at <35c0e5f206594d2fa707969117964d70>:0) UnityEditorInternal.ReorderableListWrapper.DrawChildren (UnityEngine.Rect listRect, UnityEngine.Rect headerRect, UnityEngine.Rect sizeRect, UnityEngine.Rect visibleRect, UnityEngine.EventType previousEvent) (at <35c0e5f206594d2fa707969117964d70>:0) UnityEditorInternal.ReorderableListWrapper.Draw (UnityEngine.GUIContent label, UnityEngine.Rect r, UnityEngine.Rect visibleArea, System.String tooltip, System.Boolean includeChildren) (at <35c0e5f206594d2fa707969117964d70>:0) UnityEditor.PropertyHandler.OnGUI (UnityEngine.Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, System.Boolean includeChildren, UnityEngine.Rect visibleArea) (at <35c0e5f206594d2fa707969117964d70>:0) UnityEditor.PropertyHandler.OnGUI (UnityEngine.Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, System.Boolean includeChildren) (at <35c0e5f206594d2fa707969117964d70>:0) UnityEditor.PropertyHandler.OnGUILayout (UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, System.Boolean includeChildren, UnityEngine.GUILayoutOption[] options) (at <35c0e5f206594d2fa707969117964d70>:0) UnityEditor.EditorGUILayout.PropertyField (UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, System.Boolean includeChildren, UnityEngine.GUILayoutOption[] options) (at <35c0e5f206594d2fa707969117964d70>:0) UnityEditor.EditorGUILayout.PropertyField (UnityEditor.SerializedProperty property, UnityEngine.GUILayoutOption[] options) (at <35c0e5f206594d2fa707969117964d70>:0) NavMeshPlus.Editors.Components.NavMeshModifierTilemapEditor.OnInspectorGUI () (at Assets/NavMeshComponents/Editor/NavMeshModifierTilemapEditor.cs:33) UnityEditor.UIElements.InspectorElement+<>c__DisplayClass72_0.b__0 () (at <35c0e5f206594d2fa707969117964d70>:0) UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)
@h8man
Copy link
Owner

h8man commented Oct 2, 2023

Investigation needed.

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

@snarlynarwhal
Copy link
Contributor

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);
        }
    }
}

@h8man
Copy link
Owner

h8man commented Jan 15, 2024

Thx,

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

@FoolishEL
Copy link

FoolishEL commented Apr 19, 2024

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

@h8man
Copy link
Owner

h8man commented May 12, 2024

@FoolishEL can you make Merge Request?

FoolishEL pushed a commit to FoolishEL/NavMeshPlus that referenced this issue May 12, 2024
…Tile and other classes inherited from TileBase
@FoolishEL
Copy link

@h8man
Here you are.
#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
Copy link

Снимок экрана 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

h8man pushed a commit that referenced this issue May 12, 2024
@h8man
Copy link
Owner

h8man commented May 12, 2024

Great job!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants