NavMeshPlus
NavMeshPlus copied to clipboard
Ruletiles
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.
Investigation needed.
NavMeshModifierTilemapEditor is not documented. This component still under integration into extensions system.
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);
}
}
}
Thx,
I was investigating this issue, seems bug in Unity's package. But I maybe Ill find workaround.
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.
And will look like this
@FoolishEL can you make Merge Request?
@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.
will work with all types except those that do not have a preview method defined in the custom inspector like here
Great job!