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 Nilore · Jun 15, 2011 at 06:58 AM · lightmapindexbeastunloadloadleveladditive

Removing unused lightmaps after level unload

I'm building a large explorable area for a game I'm working on, and I've got small sub-level chunks that load in and out using LoadLevelAdditive and Destroy. But I noticed that when a chunk gets destroyed, its associated lightmaps remain in the index, and if that chunk gets re-loaded again (like if the player were to turn around and go back), it loads the lightmaps for that scene into the index a second (or third, or fourth, etc...) time.

Is there any way to run a script to remove associated lightmaps from the index during runtime, something that'd be run before the Destroy, to avoid this from happening?

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

Answer by Codax · Jul 08, 2011 at 08:57 PM

To get rid of all the lightmaps in the array you can use:

         LightmapSettings.lightmaps = new LightmapData[0];
         Resources.UnloadUnusedAssets();

If you wanted to keep a certain base set of Lightmaps, you could probably make a copy of LightmapSettings.lightmaps before you load any extra areas. Then assign that array whenever you need to.

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 Nilore · Jul 20, 2011 at 01:42 AM 0
Share

Okay, well, this seemed to work fairly well at first. It does what you say it will do, and that's a step in the right direction. What I would really like is a script to remove only certain lightmaps, not removing the whole array. I tried to work with having to remove the whole array by "refreshing" the levels when a level is removed, but this results in a rather unsightly black void for a second or two before everything comes back into view.

Is there any possible way to remove only certain lightmaps from the array? Or am I stuck?

avatar image Cratesmith · May 04, 2015 at 01:53 PM 1
Share

As he mentioned, back up your Lightmap arrays before and after and store which indexes belong to which scene you loaded.

if you unload a scene you should (I havent tested this) be able to set those lightmaps in the array to null and Resources.UnloadUnusedAssets().

Downside... Resources.UnloadUnusedAssets() kills any running coroutine. So this might not be the best option.

avatar image
0

Answer by blueatwind · Mar 16, 2020 at 03:06 AM

 LightmapSettings.lightmaps = null;

my solution

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Lightmap index error 0 Answers

Unity changing locked atlas index across multiple lightmapped meshes? 1 Answer

Baked light map for level appears to be dirty 1 Answer

How to bake several objects into one lightmap with beast? 0 Answers

How to make directional lights affect lightmaps? 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