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 stevendesu · May 27, 2013 at 01:04 AM · loadingproceduralprocedural generationruntime-generationprocedural-terrain

How to instantiate prefabs in an unloaded (or just loaded) scene?

So I'm very new to Unity3D and just recently started work on my first, true, large-scale game. Thanks to the wonderful tutorial at BugZergArcade, my time has been very well spent and I've been learning quickly.

To avoid the need for artists and still allow for unlimited gameplay, I wished to implement procedural level generation. This is where the tutorials fell short. They don't have anything on world generation.

When I looked into how to make a script run at start-up the official recommendation seems to be to have an empty GameObject in the world, then attach the script to this. I foresee one of two possible problems with this, however.

  1. If the scripts run in parallel then the player may be able to move around or fall through the world before it's finished generating

  2. If the scripts run in series then I won't be able to update the GUI as the world generates, which means no "loading bars"

Does anyone have a solution for this, or are my two worries simply unfounded? Ultimately I want the final effect to be: User starts game, user sees main menu, user hits play, user sees a loading screen, user is placed in a random world.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Owen-Reynolds · May 27, 2013 at 01:51 AM

Can use a coroutine to spread out world generation over a few frames. Do about 1/4 second's worth of work, then yield for a frame. Sort of an odd system. The trick is that nothing happens while you are doing work. No frames, no drawing, no timer changing. So each frame happens when you yield.

For the player, just give the player a Paused variable. You'll probably have one anyway, for menus (or the Pause key?) Set to true when done making the level. Or you could spawn the player last (most people would have the players pre-spawned.)

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 stevendesu · Jun 15, 2013 at 11:25 AM 0
Share

This sounds like the perfect solution. How do I make a coroutine, though? Do I just insert an empty GameObject with the world generation code and sprinkle it with yield occasionally?

avatar image Owen-Reynolds · Jun 15, 2013 at 03:16 PM 0
Share

However you have the world-making code would be the same with/without a coroutine. So, yes, I have a generator function where I just "sprinkled" in a yield. The script on an empty is fine. Then just look up Coroutine in the standard docs.

Besides putting in an occasional yield return null; (let someone else have a turn; resume from here next frame,) you'd call with StartCoroutine and have to use the IEnumerator return type. But coroutines are a popular topic. Lots of examples here.

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

14 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 avatar image avatar image avatar image

Related Questions

Occlusion culling world generation runtime 0 Answers

For loop not starting from zero 0 Answers

Optimizing Procedural terrain 2 Answers

Procedural pathfinding 0 Answers

How can I represent different biomes on a Terrain object? 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