x


Only one component of type on a Gameobject at a time

Does Unity API provide a simple solution that will allow me to only allow a single script of a certain type on a Gameobject in the editor like most of the built in components?

more ▼

asked Jul 23 '11 at 10:46 PM

Blankzz gravatar image

Blankzz
246 19 20 23

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Well, not really. The best you can do is to use the Reset() event to detect duplicates. But be careful, you can't destroy the instance in Reset().
See this question for a detailed explanation / solution:
http://answers.unity3d.com/questions/63826/replace-existing-component.html

more ▼

answered Jul 23 '11 at 11:34 PM

Bunny83 gravatar image

Bunny83
46.9k 12 50 210

I didn't think so. I was going to write my own helper function but probably would have run into problems if you hadn't pointed towards that question. Thanks

Jul 23 '11 at 11:42 PM Blankzz
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1728
x312
x17

asked: Jul 23 '11 at 10:46 PM

Seen: 1281 times

Last Updated: Jul 23 '11 at 11:42 PM