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

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

Open
CodeMonkeyJC opened this issue Feb 5, 2025 · 2 comments

Comments

@CodeMonkeyJC
Copy link

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

@ChuanXin-Unity
Copy link
Collaborator

Thanks! We will check this out and update the RuleTile.

@ChuanXin-Unity
Copy link
Collaborator

Hi, the current behaviour of the RuleTile is valid and correct.

  • If there is a Rule that matches, it will use the output from the Rule. A user may specifically want a null GameObject or collider type as set up for that Rule, which your changes would override.
  • If there are no Rules that matches, then it would use the defaults as given.

To reduce any errors from having unwanted null GameObjects in a Rule when there are defaults set, in the RuleTileEditor, we will create Rules with the defaults set. This currently is not happening right now, but will be fixed in a future version of the package.

Hope this clarifies the issue!

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

2 participants