Send parameters to script attached to runtime Instatiated Prefab?

Hi there,

I couldn’t find this anywhere on forums or answers, sorry if I’ve missed it somewhere.

I’m instantiating a prefab at runtime using C#. I’d like to pass settings to scripts attached to the prefab at instantiation.

Normally if I was doing this via a class I’d pass the parameters to the Initializer of the class during the new myClass(args…) call. I assume I can’t pass args via the Instatiate function?

Is the only way to use GetComponent on the newly instantiated Prefab and call a custom Init function on the attached script?

Thanks experts!

Richard

Yes, you use GetComponent.

–Eric

Eric5h5,

Wow… That was hyperSwift! :slight_smile:

Glad I’m not missing something silly.

Thank you very much!

Richard

After you obtain a reference to the script, you can access the script public variables like this:

script.variableName = newValue;

sccrstud92,

Cool, thank you!

Richard