# Setting values in instance before Start()?

**URL:** https://discussions.unity.com/t/setting-values-in-instance-before-start/604044
**Category:** Scripting
**Tags:** Scripting
**Created:** [November 4, 2015, 3:48am UTC](https://discussions.unity.com/t/setting-values-in-instance-before-start/604044 "2015-11-04T03:48:58Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![philstrahl](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/philstrahl/32/576125_2.png) [@philstrahl](https://discussions.unity.com/u/philstrahl)
#### Post date: [November 4, 2015, 3:48am UTC](https://discussions.unity.com/t/setting-values-in-instance-before-start/604044/1 "2015-11-04T03:48:58Z")

</div>

Hey there folks. I’m pretty new so apologies for a probably silly question. Is it possible to pass an Instance some parameters before its Start() gets executed? Because this is what I’d like to do:

- Create an instance of a script

- Set some values

- Execute its Start()

My current work-around is by adding a new method`PostStart()`to the instance and calling it like this:

foo = gameObject.AddComponent();  
foo.someInitialValue = “bar”;  
foo.PostStart();

Ideally I’d love to have something like this:  
foo = new Foo(“bar”);  
but Unity tells me to use AddComponent instead of new…

---

<div class="post-metadata">

### Author: ![Azmar](https://avatars.discourse-cdn.com/v4/letter/a/919ad9/32.png) [@Azmar](https://discussions.unity.com/u/Azmar)
#### Post date: [November 4, 2015, 3:56am UTC](https://discussions.unity.com/t/setting-values-in-instance-before-start/604044/2 "2015-11-04T03:56:00Z")

</div>

Well sounds like you are trying to add the script which yes of course you will need the addComponent to add the script. After I don’t understand why you couldn’t do foo = new Foo(params); as this is a constructor and can be done. Just setup a constructor inside your class, and good to go? Best to look up constructors with Unity on how to accomplish this.

---

<div class="post-metadata">

### Author: ![Ian094](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/ian094/32/454620_2.png) [@Ian094](https://discussions.unity.com/u/Ian094)
#### Post date: [November 4, 2015, 5:10am UTC](https://discussions.unity.com/t/setting-values-in-instance-before-start/604044/3 "2015-11-04T05:10:02Z")

</div>

Use Awake()

It gets called before Start()

---

<div class="post-metadata">

### Author: ![philstrahl](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/philstrahl/32/576125_2.png) [@philstrahl](https://discussions.unity.com/u/philstrahl)
#### Post date: [November 4, 2015, 11:17pm UTC](https://discussions.unity.com/t/setting-values-in-instance-before-start/604044/4 "2015-11-04T23:17:50Z")

</div>

Thanks for your suggestions. Alright, I guess it works when I create a sub-class with a proper constructor like I head before. My error was that it was not a sub-class but a wholly separate class and that’s why Unity wasn’t allowing it.

I grasp the basics of OOP and love to compartmentalize my code but I still have a lot to learn about best practices because I am over-complicating things for myself in my little test prototype 🙂
