Can't Destroy Transform Component Error after exiting Play mode
Hi guys, I'm new to unity and I'm getting an error that reads "Can't destroy Transform component of 'TreeCollider(Clone)'. If you want to destroy the game object, please call 'Destroy' on the game object instead. Destroying the transform component is not allowed."
The TreeCollider is a prefab containing two 2d box colliders, one is for the base of the tree, and the other is a trigger for when the player moves behind the tree (I later want to make the tree transparent when the player collides with the leaves but have not implemented that yet). In fact I have written no scripts that interact with the tree yet. All I have is a 2D collider on my player character that can collide with the tree. I get the error after I exit playmode whether or not I collide with a tree during testing.
TreeCollider is instantiated by a custom tile I've made called GreenTreeTile, that I use to paint trees on a tilemap.
this is the code for my treetile
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEngine.Tilemaps;
public class TreeTile : Tile {
#if UNITY_EDITOR
[MenuItem("Assets/Create/Tiles/TreeTile")]
public static void CreateTreeTile()
{
string path = EditorUtility.SaveFilePanelInProject("Save TreeTile","New TreeTile", "asset", "Please enter a file name to save the texture to", "Assets");
if (path == "")
{
return;
}
AssetDatabase.CreateAsset(ScriptableObject.CreateInstance<TreeTile>(), path);
}
#endif
}
Answer by scyfris · Apr 08, 2018 at 04:09 AM
It did. It seems I don't get the error if the tile palette is closed when I hit play. Strange unity bug. Anyway, thankyou very much!
Answer by rolographic · Nov 20, 2018 at 09:54 PM
It was hard to find but you can fix that behavior by unchecking the Tilemap component on the Layer1 inside the palette.