Instanced RuleTiles Do Not Appear In Scene

,

When I create an instance of a rule tile it doesn’t appear in the scene view, even though I’m setting it’s Rules equal to the rules of a prefab. I’m not sure if I have to call something maybe to get it to appear? Is this a bug?

        for (int x = 0; x < gridSizeX; x++)
        {
            for (int y = 0; y < gridSizeY; y++)
            {
                RuleTileData tileData = ScriptableObject.CreateInstance<RuleTileData>();
                tileData.xCoord = x;
                tileData.yCoord = y;

                for(int i = 0; i < waterRuleTile.m_TilingRules.Count; i++)
                {
                    tileData.m_TilingRules.Add(waterRuleTile.m_TilingRules[i]);
                }

                tileDataList.Add(tileData);
                tileData.name = x + " | " + y + " " + "(" + tileData.biome + ")";
                tileMap.SetTile(new Vector3Int(x, y, 0), tileData);
                tileMap.RefreshTile(new Vector3Int(x, y, 0));
            }
        }

I also noticed there’s no collider, even when I set it equal to collidertype.sprite.

bumpingggg

I’m pretty sure the way you are creating the rule tile is the issue as it works for me pretty well, try and just accept a rule tile from the editor and set it, should work

    public class MyClass : NetworkBehaviour
    {
        [SerializeField] private RuleTile ruleTile;
        [SerializeField] private Vector3Int position;
        public void MyFunc()
        {
                    map.SetTile(position, ruleTile);
        }
    }

This works for me.

If you dont want to accept the RuleTile in from the editor then you can load the asset file from the Resources folder

Every tile has to be a unique instance, it can’t be the prefab because I want to store various data in each tile.

If I set the default sprite in script
tileData.m_DefaultSprite = waterRuleTile.m_DefaultSprite; it will appear in scene, however the Rules from the RuleTile will not update the sprites to their correct rule.

What if you instantiate it using UnityEngine.Object.Instantiate(tileToCopy)?

Sorry about this issue! Would it be possible to share the Rules that you have set for your RuleTile?

(Edit) Also, could you share how the rule matching is done for your RuleTileData class?

Sorry for the delay I’ve been quite sick this week, please see attached images.

No luck with that either :frowning:

8460674--1123313--ruletiledata.png
8460674--1123322--Untitled.png

8460674--1123307--grasstop.png
8460674--1123310--grasstile.png

@Razputin Thanks for sharing your RuleTile!

The default Rule matching will not work for new instances of the RuleTile, see source:

        public virtual bool RuleMatch(int neighbor, TileBase other)
        {
            if (other is RuleOverrideTile ot)
                other = ot.m_InstanceTile;

            switch (neighbor)
            {
                case TilingRuleOutput.Neighbor.This: return other == this;
                case TilingRuleOutput.Neighbor.NotThis: return other != this;
            }
            return true;
        }

case TilingRuleOutput.Neighbor.This: return other == this;
This will only match if the neighbour is exactly the same instance, which will never be the case.

Instead, you could override this method in your RuleTileData and change the matching criteria, depending on how you determine matches. I will make an assumption that for all your RuleTiles will match by Biome:

        public override bool RuleMatch(int neighbor, TileBase other)
        {
            if (other is RuleOverrideTile ot)
                other = ot.m_InstanceTile;

            switch (neighbor)
            {
                case TilingRuleOutput.Neighbor.This: return other is RuleTileData && this.biome == ((RuleTileData) other).biome;
                case TilingRuleOutput.Neighbor.NotThis: return other is not RuleTileData || this.biome != ((RuleTileData)other).biome;
            }
            return true;
        }

This should now allow all instances to match each other based on their biome. Do change this if my assumption is not what you want.

Hope this helps!

1 Like

Thank you! Confirmed that makes them work <3