- Home /
Inspector Assigning VS Script Find and Get ?? (efficiency)
Hello!,
As being new to this forum and Unity (sort of), I wanted to ask a first and short question to all of you (nice to be here by the way!):
I am really interested in knowing what is more efficient,
Assigning game Objects, through the Inspector?
-OR-
Finding and Getting as, Through Script?? (on the Start of the Monobehavior that is.)
I'm really interested in getting an answer to this. Thank you all in advance.
----InquisitorKaoz.
Answer by Jessy · Apr 19, 2011 at 05:25 PM
Don't assign the references at runtime. Instead, assign the references in the Editor, and you get the best of all worlds.
http://answers.unity3d.com/questions/33828/best-way-to-getcomponent-with-pragma-strict
Thank you both very much for your answers, but the thing is that I don't $$anonymous$$d assigning manually as I will not have too many objects on the game, but I neither $$anonymous$$d to write the find get coding. So on-coding or on-inspector assignation is the same for me.
What I want to know what will happen on-game, what will be more consu$$anonymous$$g for the game, to find and get variables on-Start? OR to have them already assigned from outside the game...
I ask this because I have no idea what kind of on-game-processes occur when you assign through inspector (I do not know how Unity $$anonymous$$m coded it).
But I would like to know before going too deep in my new project, as it will be extensivelly dependant on assignings (and I also plan to use the same coding for future projects, so I am doing it the most general possible).
Well, thanking any answers in advance!
Any reference that you assign in the Inspector is going to load faster than any function can populate the reference. It may not make a noticeable difference, if your scene isn't big, though. If you're going to write functions, and not drag-and-drop, then you might as well write Editor code ins$$anonymous$$d of runtime code, though.
Answer by FLASHDENMARK · Apr 19, 2011 at 05:16 PM
I find assigning objects through scripts easier that via the inspector.
One of the advantages(e.g) when Instantiateing a prefab with a target variable that variable will allways be empty unless you pause the game and put the target into the slot manualy. If you do so through script it will find the target witch is a automated(automatic?) process.
You can also look at it like this. Do you prefere manual or automatic gears in a car? It is a preference / opinion, but I find assigning objects through script has more advantages(automatic).
Oh, and by the way welcome to UnityAnswers :)
He asked about the technical side.
which is more efficient in terms of cpu cost. while assigning from scripts is more dynamic, in some places it's good to inspector assign them. When you have a built in scene objects that have a lot of components to assign, it's better save that CPUjuice and manualy assign them.
Your answer
Follow this Question
Related Questions
Efficient way to assign a value from another value 1 Answer
Accessing a function within a script assinged in inspector. 3 Answers
How to optimize code with one time use booleans 1 Answer
Better to assign components to variables or reference directly each time 3 Answers
Console telling me to assign something which is already assigned 1 Answer