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

TilesetComponent: corrupted tile causing not generating collisions for tileset object #20

Open
Jerichos opened this issue Aug 29, 2024 · 0 comments

Comments

@Jerichos
Copy link

During generation of colliders there is for some reason a tile with position of -2147483520,-2147483648.
This will cause exception: TypeSerializedProperty Error setting System.Boolean to True (System.Boolean)

repo to test, open scene Level Mountains:
https://github.com/Jerichos/my_way_of_a_ninja.git

for now workaround is to detect a tile and remove it's tile position. Here is a snippet of code:

void RebuildMesh()
	{
		if (CollisionMesh is not null)
		{
			CollisionMesh = null;
			CollisionVertices.Clear();
			CollisionFaces.Clear();
		}
		CollisionBoxes.Clear();

		if (!HasCollider) return;
		if (Layers is null) return;

		var collisionLayer = Layers.FirstOrDefault(x => x.IsCollisionLayer);
		if (collisionLayer is null) collisionLayer = Layers.FirstOrDefault();
		if (collisionLayer is null) return;

		var tilePositions = new Dictionary<Vector2Int, bool>();
		
		// WORKAROUND: Remove 
		foreach (var tile in collisionLayer.Tiles)
		{
			tilePositions[Vector2Int.Parse(tile.Key)] = true;
			if (Vector2Int.Parse(tile.Key).x < -9999999 || Vector2Int.Parse(tile.Key).y < -9999999)
			{
				Log.Info($"WORKAROUND: removing Tile position: {tile.Key}");
				// log print: WORKAROUND: removing Tile position: -2147483520,-2147483648
				tilePositions.Remove(Vector2Int.Parse(tile.Key));
			}
		}
		
		if (tilePositions.Count == 0) return;

		var minPosition = tilePositions.Keys.Aggregate((min, next) => Vector2Int.Min(min, next));
		var maxPosition = tilePositions.Keys.Aggregate((max, next) => Vector2Int.Max(max, next));
		var totalSize = maxPosition - minPosition + Vector2Int.One;
		...

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

1 participant