Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by InquisitorKaoz · Apr 19, 2011 at 04:39 PM · inspectorfindefficiencyassignget

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.

    Comment
    Add comment
    10 |3000 characters needed characters left characters exceeded
    ▼
    • Viewable by all users
    • Viewable by moderators
    • Viewable by moderators and the original poster
    • Advanced visibility
    Viewable by all users

    2 Replies

    · Add your reply
    • Sort: 
    avatar image
    1

    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

    Comment
    Add comment · Show 3 · Share
    10 |3000 characters needed characters left characters exceeded
    ▼
    • Viewable by all users
    • Viewable by moderators
    • Viewable by moderators and the original poster
    • Advanced visibility
    Viewable by all users
    avatar image InquisitorKaoz · Apr 22, 2011 at 09:07 AM 0
    Share

    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...

    avatar image InquisitorKaoz · Apr 22, 2011 at 09:07 AM 0
    Share

    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!

    avatar image Jessy · Apr 22, 2011 at 12:56 PM 0
    Share

    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.

    avatar image
    0

    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 :)

    Comment
    Add comment · Show 1 · Share
    10 |3000 characters needed characters left characters exceeded
    ▼
    • Viewable by all users
    • Viewable by moderators
    • Viewable by moderators and the original poster
    • Advanced visibility
    Viewable by all users
    avatar image Illusive-Man · Apr 24, 2018 at 01:28 PM 0
    Share

    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

    Hint: You can notify a user about this post by typing @username

    Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

    Follow this Question

    Answers Answers and Comments

    2 People are following this question.

    avatar image avatar image

    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


    Enterprise
    Social Q&A

    Social
    Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

    Footer

    • Purchase
      • Products
      • Subscription
      • Asset Store
      • Unity Gear
      • Resellers
    • Education
      • Students
      • Educators
      • Certification
      • Learn
      • Center of Excellence
    • Download
      • Unity
      • Beta Program
    • Unity Labs
      • Labs
      • Publications
    • Resources
      • Learn platform
      • Community
      • Documentation
      • Unity QA
      • FAQ
      • Services Status
      • Connect
    • About Unity
      • About Us
      • Blog
      • Events
      • Careers
      • Contact
      • Press
      • Partners
      • Affiliates
      • Security
    Copyright © 2020 Unity Technologies
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell My Personal Information
    • Cookies Settings
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    • Anonymous
    • Sign in
    • Create
    • Ask a question
    • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Explore
    • Topics
    • Questions
    • Users
    • Badges