Question by
KOWAY · Mar 06, 2018 at 08:28 PM ·
destroygameobject
I want to destroy PlayerObject, So I can not do anything because of this error.Error content: Destroying assets is not permitted to avoid data loss. If you really want to remove an asset use DestroyImmediate (theObject, true);
if (PlayerRend.sharedMaterial.color == Color.red) { Destroy(PlayerRend); } look at the code, When a player encounters the same color as himself, the player is destroyed. However, this error occurs.
"Destroying assets is not permitted to avoid data loss. If you really want to remove an asset use DestroyImmediate (theObject, true); "
and I did write DestroyImmediate(PlayerRend, true); but................ error occurs again.
"Destroying components immediately is not permitted during physics trigger/contact, animation event callbacks or OnValidate. You must use Destroy instead."
How can i solve this? I really want to have Player Object destroy;
private Color red = new Color(1, 0, 0, 1);
public Renderer PlayerRend;
public Renderer rend;
private void Update()
{
rend.material.color = Color.red;
}
private void OnTriggerEnter(Collider other)
{
if (other.tag == "Boundary")
{
return;
}
if (other.tag == "Enemy")
{
return;
}
if (other.tag == "Bolt")
{
PlayerRend.sharedMaterial.color = Color.red;
Destroy(gameObject);
Destroy(other.gameObject);
}
if (PlayerRend.sharedMaterial.color == Color.red)
{
Destroy(PlayerRend);
}
Destroy(gameObject);
Destroy(other.gameObject);
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612154041im_/https://answers.unity.com/themes/thub/images/avi.jpg)