Author Topic: Load textures only once and not every time after scene switch.  (Read 125 times)

siddhantsaxena

  • Newbie
  • *
  • Posts: 10
    • View Profile
I want to load the voxel definitions and textures only once when the scene is loaded for the first time.. and then dont destroy them on load so that that stuff can be used when we switch scene and return to the same scene once again.
The method LoadWorldTextures() is the main method that is taking a significant amount of time to execute so I want to run it only once per instance of unity and not every time the user switches scenes...I just wanted to understand what all stuff should be stored and reassigned ... I tried storing the voxelDefinitions array of VoxelPlayEnviroment and reassigning it but that didn't work.

Kronnect

  • Administrator
  • Hero Member
  • *****
  • Posts: 7262
    • View Profile
Re: Load textures only once and not every time after scene switch.
« Reply #1 on: May 27, 2021, 09:25:36 PM »
In order to achieve that, Voxel Play Environment must be marked as "DontDestroyOnLoad".

Have you tried calling DontDestroyOnLoad on the gameobject that contains Voxel Play?
https://docs.unity3d.com/ScriptReference/Object.DontDestroyOnLoad.html

Siddhant

  • Guest
Re: Load textures only once and not every time after scene switch.
« Reply #2 on: May 30, 2021, 03:55:00 PM »
Okay thanks..actually I was looking for a way to only keep resources loaded.. not the whole enviroment object.. as I may have to load a different world when the user comes to this scene again... but I did find a method called ReloadWorld I think that will work for this case.