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
0
Question by ronronmx · Oct 23, 2012 at 08:49 AM · instantiateloadlevelhud

What's best: Instantiate or LoadLevelAdditive?

I'm a little undecided on this one! Basically, I am loading the HUD on level start, and I have tried 2 different approaches.

My first approach was to create different HUD prefabs eg; HUD_TILT_CONTROLS.prefab, HUD_TOUCH_CONTROLS.prefabs, ect... Then I use a ControlsManager class where I assign all different HUD prefabs to an array of GameObject, in the editor. Than at runtime, I Instantiate() the chosen HUD prefab, and if the user changes the HUD in the pause menu for example, I then Destroy() the current HUD prefab in the scene, and Instantiate() the new one chosen by the user. This approach works fine, but I don't like the fact that the Instantiated HUD GameObject is a (clone), and I try not to Instantiate() too many things when I don't have to.

My second approach is to create new scenes for each HUD preset, and depending on the user's choice, I load the corresponding scene with LoadLevelAdditive(). I got the idea from the Penelope IOS tutorial. The nice thing about this approach is that I could also throw in other GameObjects in each scene, like the player for example, that way I can do all my testing/tweaking in each HUD scene without having to mess with the actual level scenes. And a bonus, at least in my mind, is that I don't have to Instantiate() anything, and I get the actual GameObject(s), instead of clones.

Is one approach better then the other? Like performance-wise, or organization-wise? What do you guys recommend for loading HUDs at runtime?

Thanks for your time!

Stephane

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
Best Answer

Answer by Tim-Michels · Oct 24, 2012 at 06:33 AM

Is it an option to have a kind of parent HUD-prefab with all presets childed to that gameObject? That way you only have one prefab you can change in whatever scene you like and it will automatically be updated in all your other scenes. The only thing you have to do "manually" is to make sure that your parent-prefab is present in each scene, but you could also Instantiate that prefab through code.

If that's not an option, I still suggest the prefabs solution, because it will be easier to maintain references to your objects and manage your HUD correctly.

Comment
Add comment · 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
1

Answer by Tim-Michels · Oct 23, 2012 at 09:14 AM

I personally would use prefabs instead of loading another scene additive. I don't really understand what you mean with "I don't like the fact that the Instantiated HUD GameObject is a (clone)", but I think that Instantiating your prefabs is a good choice. You could also place all HUD-objects in your scene and Enable/Disable the ones you need. That way you don't have to Instantiate/Load at runtime which will never give you any frame-hiccups. It basically all depends on the number of prefabs you want to use. If you only switch between a couple of prefabs, I would just put them all in my scene and disable the ones I don't need. Disabled gameObjects will cost practically nothing, so this is in a lot of cases the best (performance-wise) choice.

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 ronronmx · Oct 23, 2012 at 06:40 PM 0
Share

Hey Tim, thanks for your answer.

The enabling/disabling approach is nice since like you said, disabled objects don't really use any resources, and there's no need for Instantiating them. But what I forgot to mention in my question above is the fact that I don't want to have to manually add each preset to each new scene I build, so I have to create/get them at runtime.

With the Prefabs solution, I just assign each Prefab the my Controls$$anonymous$$anager GameObject - which is automatically added at, or before, runtime - that way I don't have to worry about "placing" the Prefab presets manually for each scene.

With the LoadLevelAdditive solution, it's even easier since I don't have to assign anything to Controls$$anonymous$$anager, because it doesn't need to "look" for any Prefabs, it just loads the correct HUD scene.

Like I said, both solutions works fine, but I don't know which one is the better choice for my case, and which one is faster. I am wondering if I'm overlooking any cons for the LoadLevelAdditive approach? Like what could potentially be a problem using this technique ?

avatar image ronronmx · Oct 24, 2012 at 05:40 PM 0
Share

Hi Tim, yes it is an option, I could definitively do that! I'll give it a try when I get home :)

If you move this comment into an answer, I'll accept it as the correct answer.

Thanks for the suggestions!

Stephane

avatar image Deepscorn · Sep 23, 2015 at 02:19 PM 0
Share

Tim, frame hiccups is, of course, nasty. LoadLevelAdditiveAsync() may be used to throw them away. But is seems like we have no hiccups only when both scenes share same objects to load, so they are all loaded in scene A and no hiccups occur when we call LoadLevelAdditiveAsync(B). I was hoping, that using LoadLevelAdditiveAsync() will result in faster loading of calling scene. What a dissapointment :( Looks like LoadLevelAdditive may be used only to logically separate objects in scenes. So does prefabs. $$anonymous$$nowing that we have prefab editor https://bitbucket.org/becksebenius/prefab-editor, it looks like the preffered way

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

11 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Scripting within a area in the game 1 Answer

Creating an object and setting fields before object begins running 1 Answer

Instantantiate relative to parents position 1 Answer

AddComponent() causes a "trying to create a MonoBehaviour using the 'new' keyword" warning 2 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