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 Instability · Dec 30, 2012 at 11:25 PM · instantiateprefabsceneperformance

Instantiating prefab vs loading new scene

Hi,

I have a long linear level (kind of an endless runner). It is segmented into, well, sections (containing a series of jumps or puzzles). There are two ways I can handle this:

  1. Make every section in its own scene. Since both player and camera DontDestroyOnLoad(), there are occasional hiccups (loading scene) but it is a continuous experience. Advantage: Scenes are easy to edit. Disadvantage: Loading scene is heavy operation.

  2. Make the segments into a prefab each and put them all into one scene. They will be instantiated and destroyed as the player is onTriggerEnter() and onTriggerExit(), respectively. Note that the scenes from option 1. and the prefabs from option 2. contain the same objects, they are basically equivalent. Advantage: Maybe prefab instantiation / destruction are faster than loading scenes. Disadvantage: Inconvenient to edit; most prefabs must be erased from hierarchy before running since they are instantiated in runtime.

Which would you favour / recommend? I am inclined to 1. since scenes are easier to edit. Curious to hear your opinion.

Comment
Add comment · Show 2
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 whydoidoit · Dec 30, 2012 at 11:31 PM 0
Share

Have you thought of using LoadLevelAdditiveAsync?

avatar image Instability · Dec 30, 2012 at 11:40 PM 0
Share

Yes, but I actually want the sections that the player has beaten to be destroyed. They contain too many unrelated and computationally heavy objects like joints and (everyone - with - everyone type interactions). I want that gone for good when it's not needed.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Owen-Reynolds · Dec 31, 2012 at 01:01 AM

You could have the "to be yet seen" objects simply inactive. They would probably take very little memory -- possibly just as much as prefabs+spawning code. And, you could edit them right there and check them inactive when done. For ease, put each 50 foot section into a parent object.

For prefabs, the 50 foot section trick might help. Could edit each section normally. When done, drag them all into their prefabs and delete. The cool part is, dragging into the Heirachy pane will put them where they started (unlike dragging into the Scene, which picks a new position.) Spawning them could also key off the preFab position.

Prefabs with prefabs in them (like a long hallway with only prefab benches, lamps ... ) should still give all the space-saving advantages. For example, if section 12 is the same as section 5, could just drag the section 5 prefab into S12, with the new location (and some extra plants or something.) The section 12 prefab will only need a handful of bytes to store the location and the S5 link.

Comment
Add comment · Show 2 · 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 Instability · Dec 31, 2012 at 01:07 AM 0
Share

I thought about this but I have a problem here. An important part of my game is a static list to which an object is added on Start() and removed onDestroy(). If I have N such objects, every FixedUpdate() iteration checks N^2 interactions. The inactive objects would take up space in the list which is not good... There don't seem to be functions like onActivate or onDeactivate which would be helpful here...

That's why I was thinking about 'hard' things like destruction of a prefab or loading a new scene. This way, each prefab / scene contains a manageable number of objects at a time, so I keep few interactions at a time.

avatar image Owen-Reynolds · Dec 31, 2012 at 03:14 AM 0
Share

It's your list -- no reason you can't add/remove objects when you (de)/activate them, if you want. You may have to hand-add the ones at scene start (or pre-add everything with a certain tag.)

A compare all-to-all every frame? Unity does most of that for you, using tricks to run faster. Sure you can't get rid of that?

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

10 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

Related Questions

How can i transfer an object from scene1 and instantiate it in scene2? 2 Answers

Are the prefabs stored in RAM or in the Hard disk? 0 Answers

Instantiating in Awake() v Setting up prefab instances in Editor performance difference? 1 Answer

Save gameobjects prefabs from scene A to a list, then instantiate those game objects to another scene. 0 Answers

How do you make a script that creates a new scene on runtime? 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