Adding other components automatically?

Hi,

I’m looking for a solution to handle adding other components to a game object when my script component is added. I’d assume there is a editor event or something to override, however I can’t seem to find the correct function. I’ve googled and read the documentation, perhaps i missed it out?

Anyone care to enlighten me? Thanks!

Bryan,

I think the RequireComponent attribute is what you are looking for. It lets you specify another component that your script requires and it will add it automatically when you drag your script onto an object.

I hope this helps: Unity - Scripting API: RequireComponent