x


Editor Script for attaching components to game object on creation

Hi there, I am looking for this for quite some time now. i have a big level with several game objects. I want a certain scripts to be attached to the object when it is created or a pop up window to be displayed when a new object is created. I have done the window part but it is working with menu item now. What exactly i need is a function like OnCreate or something, that would call this window automatically. or any simple work around is accepted.

Problem is the designer misses out on adding scripts to a lot of game objects, which is wasting a lot of my time..

more ▼

asked May 30 '12 at 06:33 AM

flamy gravatar image

flamy
3.5k 5 11 37

Good question.

You can always do: while (designer != Concentrated) { ReplaceDesigner(); }

May 30 '12 at 07:00 AM GuyTidhar

haha true, in this case cant help it, attaching to 600+ invidual objects + its children. even i would get tired .

And good designers are real hard to find anyway :P

May 30 '12 at 07:04 AM flamy
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Don't blame the designer :P

Suggestions:

  • Liberal use of [RequireComponent(typeof(MyAmazingComponent))]
  • Gently and ever so politely encourage designer to test what they create.
  • Provide designer with template prefabs they can duplicate that come prepackaged with the required scripts
  • Slightly less gently remind designer to test what they create
  • Create a script that is somewhere in the scene that is constantly checking (even in Edit mode - [ExecuteInEditMode]) that objects have the required scripts and provides errors as required
  • Don't just log errors to the console, create a popup that has to be dismissed. Your designer might not be a technical person, don't assume they read logs
  • Even less gently remind the designer that they MUST test everything they create... otherwise how do they know their design is good? What kind of designer isn't constantly testing?
more ▼

answered May 30 '12 at 07:07 AM

tomka gravatar image

tomka
283 3 6 9

you got some really valid points(especially the popup one). but,

RequireComponent cannot be used in this case because there is no script attached to the GO that is the problem. And the editor window i have created would take care of what components to be attached.

My main motive is to save both our time. he need not test every little thing he has created. That is the reason i have done editor scripts even.

May 30 '12 at 07:14 AM flamy
(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:

x1671
x39
x31

asked: May 30 '12 at 06:33 AM

Seen: 505 times

Last Updated: Jun 11 '12 at 06:18 AM