How to instatinate RenderSettings in script?
Could someone show me how to save RenderSettings? I wrote c# script below in vain:
private RenderSettings originalRenderSettings;
...
originalRenderSettings = Instantiate(RenderSettings);
What is RenderSettings belonging to?
Answer by Statement · Oct 27, 2015 at 02:38 PM
I think you 99% of cases want to use the static variables exposed on the class. RenderSettings belong to the currently loaded scene.
RenderSettings.fog = true;
I don't think you should have more than one render setting per scene. Anyway, it is an UnityEngine.Object, so the following should work (but I don't know what the expected behaviour of it would be).
// Every scene has a RenderSettings, so let's get it.
RenderSettings settings = Object.FindObjectOfType<RenderSettings>();
// NOTE! Now you get TWO RenderSettings!
// This will probably confuse the *heck* out of Unity.
RenderSettings clone = (RenderSettings )Object.Instantiate(settings);
Or if you just want to create a new RenderSetting I think it's just
RenderSettings newSettings = new RenderSettings();
If it has a public constructor...
Thank you, it works! ....and I'd like to ask one more: how to restore
I want to modify the existing, and change them back.
$$anonymous$$eep track of the variables in runtime.
// Save the original setting.
bool originalFog = RenderSettings.fog;
// Change the setting.
RenderSettings.fog = true;
// Restore the setting.
RenderSettings.fog = originalFog;
If you want to support Undo etc in Editor (will not run on built games), use the Undo system. Perhaps RecordObject is a place to start.
I see. It ought to have possible to restore at once! Thank you again!!
Your answer
![](https://koobas.hobune.stream/wayback/20220612042932im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to instantiate a game object every time when space key is pressed 2 Answers
Can You help me Fix This? (Infinite level Generator) 0 Answers
Why does NetworkServer.ReplacePlayerForConnection not recognize the instantiated object parameter? 0 Answers
Object Reference Not Set to an Instance of an Object? 0 Answers