• 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
Question by rt_jscott · Jan 31, 2018 at 10:03 PM · sceneperformancescene-loadingactivate

How can I prevent frame spikes when activating parts of a level?

My project has large linear scenes the player travels through. For performance, we group the scenes in to chunks and keep them "inactive" and set them active when the player gets close to them. My problem is that calling the call to SetActive can cause a large (> 33ms) frame spike. Is there a better way to go about this?

It would be fine if the time spent was at before the level starts, but it seems to have no effect to leave every section active for a few seconds before hiding it.

Comment

People who like this

0 Show 0
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

  • Sort: 
avatar image

Answer by KriskyD · Jan 31, 2018 at 10:19 PM

It may be caused by loading new objects or shaders for the first time. An easy solution is to leave all your chunks active in the scene and set them inactive after game starts. Another way around is to read about Unity methods like Shader.WarmupAllShaders() and similar and to try them out.

Comment

People who like this

0 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 rt_jscott · Jan 31, 2018 at 10:38 PM 0
Share

Yes, I think this is part of the problem but there are other issues as well. I still see the spikes even when I do leave them active for a few seconds. I also am using Shader.WarmupAllShaders at level start as well. Even still GameObject.Activate still takes a long time...

avatar image KriskyD rt_jscott · Feb 01, 2018 at 02:03 PM 0
Share

@rt_jscott Try using Coroutines. You can save every gameObject in chunk to list or array and then activate few of them in every frame with one function.

avatar image rt_jscott KriskyD · Feb 01, 2018 at 03:04 PM 0
Share

Oh that's a very good idea! I'll try that out. Thanks!

avatar image

Answer by Friedemann_A · Feb 01, 2018 at 02:48 PM

I don't know if this works for you as it would probably require lots of rework in your scene-structure but I think many people split their bigger levels up into multiple scene and use LoadSceneAsync for stuff like this: https://docs.unity3d.com/ScriptReference/SceneManagement.SceneManager.LoadSceneAsync.html

If you've played "Inside" I think that's what they used there for example.
Hope this helps!

Comment

People who like this

0 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 rt_jscott · Feb 01, 2018 at 03:07 PM 0
Share

In fact we've already split our level up in to multiple scenes just so that we can have multiple people work on them. We've got enough memory to load them all, so I hadn't considered bothering to LoadSceneAsync them. Thanks!

avatar image Friedemann_A rt_jscott · Feb 01, 2018 at 04:33 PM 0
Share

Nice, glad I could help :)

Unity Answers is in Read-Only mode

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta by June 9. Please note, Unity Answers is now in read-only so we can prepare for the final data migration.

For more information and updates, please read our full announcement thread in the Unity Forum.

Follow this Question

Answers Answers and Comments

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

Related Questions

Scene assets not bundled in asset bundle 0 Answers

SetActive in another scene 2 Answers

Loading a scene 1 Answer

Client player cannot see MasterClient player after scene change 0 Answers

Creating separate scenes for one game 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