Skip to content

RuleTile implementation does not honor Default GameObject set in editor #391

Description

@CodeMonkeyJC

In the GetTileData method of the RuleTile script the gameObject is initially set to the default object (line: 206) in the RuleMatches if statement the "defaults" for the gameObject and collider type are always overwritten even if null. Lines 233/234.

Here is a solution i used:
if (RuleMatches(rule, position, tilemap, ref transform))
{
switch (rule.m_Output)
{
case TilingRuleOutput.OutputSprite.Single:
case TilingRuleOutput.OutputSprite.Animation:
tileData.sprite = rule.m_Sprites[0];
break;
case TilingRuleOutput.OutputSprite.Random:
var index = Mathf.Clamp(
Mathf.FloorToInt(GetPerlinValue(position, rule.m_PerlinScale, 100000f) *
rule.m_Sprites.Length), 0, rule.m_Sprites.Length - 1);
tileData.sprite = rule.m_Sprites[index];
if (rule.m_RandomTransform != TilingRuleOutput.Transform.Fixed)
transform = ApplyRandomTransform(rule.m_RandomTransform, transform, rule.m_PerlinScale,
position);
break;
}
tileData.transform = transform;
tileData.gameObject ??= rule.m_GameObject;
if (rule.m_ColliderType != m_DefaultColliderType)
tileData.colliderType = rule.m_ColliderType;

break;
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions