Why Unity uses reflection to get the update method?
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
1
down vote
favorite
Why Unity uses reflection in order access to MonoBehaviour
messages methods like Awake
, Update
, Start
,...?
Wouldn't be slow to use reflection? Why it doesn't leverage other approaches like Template Method
? It could simply define the methods as abstract in MonoBehaviour base class and force the subclasses to implement it.
So as you see in the answer my assumption was wrong. However, the
answer can be useful for users hence I kept the post.
unity c# performance
add a comment |Â
up vote
1
down vote
favorite
Why Unity uses reflection in order access to MonoBehaviour
messages methods like Awake
, Update
, Start
,...?
Wouldn't be slow to use reflection? Why it doesn't leverage other approaches like Template Method
? It could simply define the methods as abstract in MonoBehaviour base class and force the subclasses to implement it.
So as you see in the answer my assumption was wrong. However, the
answer can be useful for users hence I kept the post.
unity c# performance
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
Why Unity uses reflection in order access to MonoBehaviour
messages methods like Awake
, Update
, Start
,...?
Wouldn't be slow to use reflection? Why it doesn't leverage other approaches like Template Method
? It could simply define the methods as abstract in MonoBehaviour base class and force the subclasses to implement it.
So as you see in the answer my assumption was wrong. However, the
answer can be useful for users hence I kept the post.
unity c# performance
Why Unity uses reflection in order access to MonoBehaviour
messages methods like Awake
, Update
, Start
,...?
Wouldn't be slow to use reflection? Why it doesn't leverage other approaches like Template Method
? It could simply define the methods as abstract in MonoBehaviour base class and force the subclasses to implement it.
So as you see in the answer my assumption was wrong. However, the
answer can be useful for users hence I kept the post.
unity c# performance
unity c# performance
edited 4 hours ago
asked 6 hours ago
Emad
462613
462613
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
3
down vote
accepted
It doesn't
How Update is called
No, Unity doesnâÂÂt use System.Reflection to find a magic method every time it needs to call one.
Instead, the first time a MonoBehaviour of a given type is accessed the underlying script is inspected through scripting runtime (either Mono or IL2CPP) whether it has any magic methods defined and this information is cached. If a MonoBehaviour has a specific method it is added to a proper list, for example if a script has Update method defined it is added to a list of scripts which need to be updated every frame.
During the game Unity just iterates through these lists and executes methods from it â that simple. Also, this is why it doesnâÂÂt matter if your Update method is public or private.
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
accepted
It doesn't
How Update is called
No, Unity doesnâÂÂt use System.Reflection to find a magic method every time it needs to call one.
Instead, the first time a MonoBehaviour of a given type is accessed the underlying script is inspected through scripting runtime (either Mono or IL2CPP) whether it has any magic methods defined and this information is cached. If a MonoBehaviour has a specific method it is added to a proper list, for example if a script has Update method defined it is added to a list of scripts which need to be updated every frame.
During the game Unity just iterates through these lists and executes methods from it â that simple. Also, this is why it doesnâÂÂt matter if your Update method is public or private.
add a comment |Â
up vote
3
down vote
accepted
It doesn't
How Update is called
No, Unity doesnâÂÂt use System.Reflection to find a magic method every time it needs to call one.
Instead, the first time a MonoBehaviour of a given type is accessed the underlying script is inspected through scripting runtime (either Mono or IL2CPP) whether it has any magic methods defined and this information is cached. If a MonoBehaviour has a specific method it is added to a proper list, for example if a script has Update method defined it is added to a list of scripts which need to be updated every frame.
During the game Unity just iterates through these lists and executes methods from it â that simple. Also, this is why it doesnâÂÂt matter if your Update method is public or private.
add a comment |Â
up vote
3
down vote
accepted
up vote
3
down vote
accepted
It doesn't
How Update is called
No, Unity doesnâÂÂt use System.Reflection to find a magic method every time it needs to call one.
Instead, the first time a MonoBehaviour of a given type is accessed the underlying script is inspected through scripting runtime (either Mono or IL2CPP) whether it has any magic methods defined and this information is cached. If a MonoBehaviour has a specific method it is added to a proper list, for example if a script has Update method defined it is added to a list of scripts which need to be updated every frame.
During the game Unity just iterates through these lists and executes methods from it â that simple. Also, this is why it doesnâÂÂt matter if your Update method is public or private.
It doesn't
How Update is called
No, Unity doesnâÂÂt use System.Reflection to find a magic method every time it needs to call one.
Instead, the first time a MonoBehaviour of a given type is accessed the underlying script is inspected through scripting runtime (either Mono or IL2CPP) whether it has any magic methods defined and this information is cached. If a MonoBehaviour has a specific method it is added to a proper list, for example if a script has Update method defined it is added to a list of scripts which need to be updated every frame.
During the game Unity just iterates through these lists and executes methods from it â that simple. Also, this is why it doesnâÂÂt matter if your Update method is public or private.
answered 5 hours ago
Draco18s
4,9741128
4,9741128
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgamedev.stackexchange.com%2fquestions%2f164892%2fwhy-unity-uses-reflection-to-get-the-update-method%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password