• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This question was closed May 07, 2018 at 08:15 AM by Myth for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Myth · Feb 03, 2011 at 02:56 AM · gameobjectmeshdestroyrendererissue

Can't remove component. MeshRenderer depends on it

What can I do about this error?

Currently I have an object that should die (Destroy currently) when health <= 0 and instead I get this error

here is the code that should rid me of the object:

// vars var health : float = 100; var armour : float = 0; var shield : float = 0;

// supporting vars var damage_hull : float = 0; var damage_shield : float = 0; var temp : float = 0;

// control vars var replace : boolean = false;

// objects var explosion : Transform; var replacement : Transform; var origional : Transform;

function Update () { if (health > 0.0 && shield <= 0.0) { if (armour > 0) { armour = armour - ( damage_hull / 2 ); temp = damage_hull - armour; if (temp > 0) { damage_hull = temp; } }

     health = health - damage_hull;
 }

 if (health &lt;= 0.0)
 {
     if (replace == false)
     {
         //Instantiate(explosion,transform.position, transform.rotation);
         Destroy (origional);
     }
     else
     {
         Instantiate(replacement,transform.position, transform.rotation);
         Destroy (origional);
     }
 }

}

function Hull_Damage_receiver (hull : float) { damage_hull = hull; }

function Shield_Damage_receiver (shield : float) { damage_shield = shield; }

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image DaveA · Feb 03, 2011 at 03:53 AM 0
Share

How are replacement and origional getting set?

avatar image Myth · Feb 03, 2011 at 04:17 AM 0
Share

Drag and drop into the inspector - I think?

avatar image Myth · Feb 03, 2011 at 04:18 AM 0
Share

Why? Does it make a difference in Unity? - I'm fairly new to it.

1 Reply

  • Sort: 
avatar image
2
Best Answer

Answer by Molix · Feb 03, 2011 at 03:53 AM

Since "origional" is a Transform, I think you probably want:

Destroy( origional.gameObject );
Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Myth · Feb 03, 2011 at 04:17 AM 0
Share

Thanks a lot - still can't get my head around it though!

avatar image Molix · Feb 03, 2011 at 05:17 AM 1
Share

If you Destroy the Transform (a Component), it is like trying to remove the Transform component from the GameObject. However, all Components expect there to be a Transform in their GameObject, so it complains.

avatar image Myth · Feb 03, 2011 at 06:07 AM 0
Share

Thanks for that.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers

Animation : Mesh Renderer - Issue 0 Answers

c#: Best practice to toggle visiblity of meshes within a gameObject? 2 Answers

Destroying all enemy characters after the level is over 4 Answers

Animator.Rebind() not working as expected after manually changing GameObject hierarchy 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges