Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 SalvoSoftware · Oct 25, 2015 at 12:21 AM · gameobjectinstantiatelagasynchronous

Do Asynchronous GameObject.Instantiate Exists?

Hi! I'm making a procedural game, and I've made a system that Instantiates/Destroys GameObjects, to avoid lag, based on distance.

The only problem is that some of the prefabs that needs to be spawned are complex, and when they spawn/destroy they cause annoying frame-rate drops.

Is there a way to do a sort of Asynchronous GameObject.Instantiate, so the frame-rate drops are less annoying? (Or if you know another way to avoid this problem)

Comment
Add comment · Show 1
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 Ymrasu · Oct 25, 2015 at 04:41 AM 1
Share

What you are looking for is called Object Pooling, Unity has provided a tutorial on the subject HERE

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by MrMeows · Oct 25, 2015 at 04:44 AM

Use SetActive instead of instantiating and destroying. That way, the GameObjects remain in the scene but require no processing.

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 SalvoSoftware · Oct 25, 2015 at 08:15 AM 0
Share

I've tried that before, but the game lags. It's probably because meshes are still processed by the engine, just not rendered.

For lag I mean 1-2 fps. (unfortunately it's more than 800 objects)

avatar image MrMeows SalvoSoftware · Oct 25, 2015 at 04:52 PM 0
Share

I can think of no reason why anything would be processed. I am suspicious that the active GameObjects are enough to cause the lag. Run the profiler (Ctrl+7) to find the cause. If it actually is rendering, you can reduce your quality settings. However, I usually have problems with OnTriggerStays, and there are few, if any, ways to alleviate that.

avatar image
0

Answer by josh-carberry · Oct 30, 2021 at 08:44 AM

Use the unity.addressable package https://docs.unity3d.com/Packages/com.unity.addressables@0.4/manual/index.html

you can find a function called InstantiateAsync

 public async Task LoadAddress(string path)
 {
     AsyncOperationHandle<GameObject> op = Addressables.InstantiateAsync(path);
     op.Completed += OnLoadDone;
     await op.Task;
 }
 void OnLoadDone(AsyncOperationHandle<GameObject> op)
 {
     GameObject obj = op.Result;
     //Do stuff
 }

You can then set that up in an async thread and await op.task you can add functions to the op.Completed Action and they will run when it is complete. To load them all in at once you can skip the await but i wouldn't advise that for large files.

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

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Instantiating a gameobject causes a lagspike 2 Answers

Best way to display scores appearance 1 Answer

Lag when activating GameObjects 5 Answers

Instantiate fails with no errors 0 Answers

Unwanted 2nd empty gameobject 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