Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
This question was closed Nov 17, 2016 at 10:46 PM by hexagonius for the following reason:

The question is answered

avatar image
0
Question by joshuauhler · Nov 17, 2016 at 02:59 PM · gameobjecteditorprefabscript.

Scripted GameObjects vs Prefabs

I have read that coding with GameObjects names as strings can be bad, due to the ease of renaming. Should I build my GameObjects in code or keep using prefabs? Ideally these GameObjects designs shouldn't change, but I might want to change the names at some point in the future.

Thank you.

Comment
Add comment · Show 4
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 Filhanteraren · Nov 17, 2016 at 04:39 PM 0
Share

Do you have any example code so it is easier to understand what you intend to do?

avatar image joshuauhler · Nov 17, 2016 at 05:24 PM 0
Share

I'm not at my computer right now, but I will try to explain it better.

With a prefab you can use a Resources.Load (path/name). However if I go to the prefab in the suite I can rename it, which breaks all the Resources.Load ().

An alternative is to make a c# class ins$$anonymous$$d of a prefab, which sets all the components fields in its start method. If I change the gameObjects name field it won't break the code. Likewise if I change the class name, it will ask if I want to refactor my project. $$anonymous$$eaning it still wouldn't break my code.

Which would you suggest?

avatar image hexagonius · Nov 17, 2016 at 09:28 PM 0
Share

if you are a fan of writing configuration code for hours, basically replacing the fast and efficient possibilities one have with the inspector, than it's the way to go. But if you ask me I'd rather have a bad name three times a project than program$$anonymous$$g configurations.
You could also just have one class handling the path finding so the strings exist only once. If you must, implement a debug function that checks all gameobjects for their existence in the resources folder. just a side note, animations are also string bound and probably the bigger problem.

avatar image joshuauhler · Nov 17, 2016 at 09:57 PM 0
Share

Oh, I forgot I could just make a file with the prefab names. Thank you.

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

GameObject changes to None in inspector after pressing Play 0 Answers

How to attach a GameObject to a Prefab that has many scripts attached? 0 Answers

Why does GameObject.FindWithTag() get a wrong instance? 2 Answers

How can I change the root game object of a prefab in the editor? 1 Answer

Quiz Game Management 0 Answers


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