- Home /
When JS scripts compiles into a dll, the Start, Update, etc methods all are 'overrides'? and... there's also a 'Main' method?
So I was messing with manual compilation a bit, and compiled a simple JS script into a dll:
TestJs.js
#pragma strict
function Update() { }
function Start() { }
I looked at the generated dll, and was quite surprised...
I'm not a JS dude, so I could be missing something simple. But, what are we 'overriding', and who the hell is this "Main"?!
$$anonymous$$ain() is the Universal Entry point.
Which languages do you know (not necessarily for Unity)? A good few I assume.
I have to be honest, I'm quite new to JS but I do know that in JS $$anonymous$$ain() is just another function, not like the one in C, for example. I imagine it's there for convention. Perhaps as a helper function. In the stats window rests the '$$anonymous$$ain Thread' time so this could indicate some forced entry point or C compatibility function.
As a guess.
There was a thread on this site recently about $$anonymous$$ain(), but I can't now find it.
From simple tests, it appears that any code placed inside $$anonymous$$ain() in a $$anonymous$$onoBehaviour will be called after Awake() but before Start(), but given it's undocumented and doesn't provide any functionality beyond those two existing hooks, I would personally leave it alone. Interesting to note that it exists in the compiled dll as well though.
Ok :) Thanks for the clarification.
I learned program$$anonymous$$g as an Engineer. Still getting to grips with the Computer Sciency aspect of program$$anonymous$$g :D
Answer by Landern · Jun 20, 2014 at 04:01 PM
But, what are we 'overriding', and who the hell is this "Main"?!
You're overriding the base implementation that exists in MonoBehavior in favor of your implementation, the state machine needs to have some consistency when calling methods.
Main is just a another method available, probably not documented due to UT either not expecting a user to override it typically or it has a very particular execution path that is generally covered by Awake/Start.
You're overriding the base implementation that exists in $$anonymous$$onoBehavior
Start
, Awake
, Update
etc are not located in $$anonymous$$onoBehaviour
- They're called from the C++ side - See Lucas's comments at the end of this blog (which kind of drifted away at the end...)
Your answer
Follow this Question
Related Questions
How to use (AVPro) plugin with JavaScript. 1 Answer
unity allow player to script a object or compile and run a code in runtime 1 Answer
Why can't I build Web Player in Unity while I have no problems with building standalone versions? 2 Answers
How do you compile a managed dll with mono/mcs targeting .net 2.0 or 3.5 for Unity? 1 Answer
Including a DLL in unity? 1 Answer