# How to make different Rule Tiles interact with each other?

I am using Unity's RuleTiles to automatically change sprites of adjacent similar blocks.

For example, when a Dirt tile notices there are two Dirt tiles to the left and the right of it, it will change texture, like this:

I would also like to do this with walls. However, I plan to have many types of walls (Wood, Stone, Metal). How would I make different types of walls still affect each other?

Imagine that Dirt is now a Wood wall. If I place a Stone wall to the left, and a Metal wall to the right, I'd still like for it to apply a texture change.

Is it possible to make different types of rule tiles interact with each other?

• is it possible to use inheritance. So you can have a base class Wall then the Wood, Stone, Metal etc can extend that class. Then you just check if it is type Wall Jun 8 '21 at 15:43
• Perhaps but this seems like it would require coding an entire system. Unity RuleTiles already do this, I'm just wondering if it's possible to extend that functionality to connect different RuleTiles. Jun 8 '21 at 15:56

For my purposes, this example from Unity's Github worked flawlessly (Source):

public class ExampleSiblingRuleTile : RuleTile
{

public enum SiblingGroup
{
Poles,
Terrain,
}
public SiblingGroup siblingGroup;

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

switch (neighbor)
{
case TilingRule.Neighbor.This:
{
return other is ExampleSiblingRuleTile
&& (other as ExampleSiblingRuleTile).siblingGroup == this.siblingGroup;
}
case TilingRule.Neighbor.NotThis:
{
return !(other is ExampleSiblingRuleTile
&& (other as ExampleSiblingRuleTile).siblingGroup == this.siblingGroup);
}
}

return base.RuleMatch(neighbor, other);
}
}



In my case, I'd have a single value in the SiblingGroup enum, Wall. Then I'd create multiple instances of the ExampleSiblingRuleTile, and assign the Wall value to them. Now they will all react to neighbor tiles and update their textures accordingly.

• It's still a good idea to include the source link for credit and further reading, so you don't have to delete that from your answer. The goal is to just not rely solely on links without any explanation in the text of the answer. Jun 25 '21 at 11:24