Game Development Asked on December 15, 2021
Usually in Unity, when your scripts make changes to something at runtime, those changes are not persisted back to design-time. This is generally considered a good thing. But for whatever bizarre technical reason, this does not apply to shader properties on materials. If you change something while the game is running, it stays changed!
Generally the way to get around this is with a MaterialPropertyBlock
, which also helps avoid generating a lot of garbage. But MaterialPropertyBlock
s work with Renderer
s, which leaves out one rather important material: the skybox.
Right now, I have code that says RenderSettings.skybox.SetFloat("_PropName", value);
, and it’s incredibly aggravating because it always needs to be reset afterwards. RenderSettings
doesn’t have a SkyboxRenderer
property that I can use in conjunction with a MaterialPropertyBlock
, so how can I change shader settings on my skybox and make them not persist after I exit play mode?
Presumably you considered doing something like...
Material originalSkybox = RenderSettings.skybox;
Material runtimeSkybox = Instantiate(originalSkybox);
RenderSettings.skybox = runtimeSkybox;
runtimeSkybox.SetFloat(...
...and destroying runtimeSkybox
when your game ends?
Answered by DMGregory on December 15, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP