WinMain() or main()

Can someone tell me where the game starts?

Which script gets called first? What game objects get instantiated first? How to control game object instantiation order?

I wanted to move the soldier from the Bootcamp demo into a test project. But a reference variable is always returning null. The object is not instantiated and the “Start” method or the component is never called.

Thanks for the help.

Neither, there is no main function to hook in.

each component is initiated on its own, calling order on a new monobehaviour is Awake → Start → Update

Thanks for responding dreamora.

Do you know what would cause a reference to not be instantiated? GetComponent() is returning null.

How do you add it?
If you add it as monobehaviour directly on the game object in editor, GetComponent from somewhere outside of it should return something if you search for the right type on the right game object.
if you add it through code, then you would have used AddComponent and could have casted the result of that (if you don’t cast it, it won’t work) directly and it worked

some sample code would make most sense in this case.

I don’t have the specifics with me right now but I will post the details later.

The reference component in question is a member of the script and it is assigned via the Inspector.

So you use getcomponent to the script and cast the return to your target class, then you access the public field within it to which you assigned the other component, right?

refVar = GetComponent( “name” );

refVar.field = value;

refVar is null.

The type casting is missing there. unless you work with unity 2.x and unityscript, that getcomponent will fail.

also, i would recommend to NEVER use strings for get component. always use the type so you get errors for missing classes etc already at compilation

The type casting may already be there, I will have to check it.

The string verses data type is an interesting issue. In a different project I tried the GetComponent without the string and I was getting an error. The only way I could get it to work was with a string, and the return type was type casted appropriately.