code a unity script for Unity 2022.3 Builtin, to adjust Material smootheness at runtime for the runtime selected prefab
Assistant
Certainly! Below is a Unity C# script compatible with Unity 2022.3 (Builtin Render Pipeline) that allows you to adjust the smoothness of a runtime-selected prefab's material during runtime.
How it works:
You assign a prefab or instantiate it at runtime.
The script exposes a public method SetSmoothness(float smoothness) where smoothness ranges from 0 (rough) to 1 (smooth).
The script assumes the material uses the Standard Shader (or any shader that has a _Glossiness property) to adjust smoothness.
Script: SmoothnessAdjuster.cs
csharp
using UnityEngine;
public class SmoothnessAdjuster : MonoBehaviour
{
// The instance of the prefab or GameObject whose material will be adjusted.
// Assign this dynamically when you instantiate the prefab or drag in the editor if you already have it.
public GameObject targetObject;
// Optional: the material index to adjust if the target object has multiple materials
public int materialIndex = 0;
// Cached Renderer
private Renderer targetRenderer;
private Material targetMaterial;
void Start()
{
if (targetObject == null)
{
Debug.LogError("Target Object not assigned.");
return;
}
targetRenderer = targetObject.GetComponent<Renderer>();
if (targetRenderer == null)
{
Debug.LogError("Target Object has no Renderer component.");
return;
}
if (materialIndex < 0 || materialIndex >= targetRenderer.materials.Length)
{
Debug.LogError("Material Index out of range.");
return;
}
// IMPORTANT: Use .materials to get a copy of the materials, so changing this does not affect shared materials globally
Material[] mats = targetRenderer.materials;
targetMaterial = mats[materialIndex];
// Re-assign to apply the copied materials to the renderer
targetRenderer.materials = mats;
}
/// <summary>
/// Adjust the smoothness of the target's material.
/// Smoothness: 0 (rough) to 1 (smooth)
/// </summary>
/// <param name="smoothness"></param>
public void SetSmoothness(float smoothness)
{
if (targetMaterial == null)
{
Debug.LogError("Target material not set.");
return;
}
// Clamp between 0 and 1
smoothness = Mathf.Clamp01(smoothness);
// Standard shader uses _Glossiness property for smoothness
if (targetMaterial.HasProperty("_Glossiness"))
{
targetMaterial.SetFloat("_Glossiness", smoothness);
}
else
{
Debug.LogWarning("Material does not have _Glossiness property.");
}
}
}
How to use this script
Attach this script to any active GameObject in your scene (e.g., an empty GameObject).
Assign your prefab GameObject instance at runtime to the targetObject field, or assign it in the inspector if your prefab is already in the scene.
Call the SetSmoothness(float) method to adjust the smoothness.
Example: Instantiating and adjusting smoothness at runtime
You can extend this script or another manager script like this:
csharp
public class ExampleUsage : MonoBehaviour
{
public GameObject prefabToSpawn;
private SmoothnessAdjuster smoothnessAdjuster;
void Start()
{
GameObject instance = Instantiate(prefabToSpawn, Vector3.zero, Quaternion.identity);
smoothnessAdjuster = gameObject.AddComponent<SmoothnessAdjuster>();
smoothnessAdjuster.targetObject = instance;
// Set smoothness to 0.75 (you can change at runtime)
smoothnessAdjuster.SetSmoothness(0.75f);
}
}
If you want I can help build a UI to adjust smoothness live using a slider or keys, just ask!
User
i want to attach the script to the prefab in the inspector and I will use a slider in my UI, so that whenever the user selects a prefab that has this script attached, the Smoothness slider should adjust the values. Adjust the script and show the whole script
Assistant
Got it! You want a script attached to the prefab itself, exposing a public SetSmoothness(float) method that modifies the attached prefab’s material smoothness at runtime. Then, a UI slider can call that method on the currently selected prefab.
I will write the complete script to be attached to the prefab — it will:
Cache its own Renderer and Material on Awake.
Expose a public SetSmoothness(float) method.
Optionally, it will clamp the input between 0 and 1.
Support multiple materials by adjusting the smoothness on all materials that have _Glossiness.
Here is the complete script PrefabSmoothness.cs:
csharp
using UnityEngine;
[RequireComponent(typeof(Renderer))]
public class PrefabSmoothness : MonoBehaviour
{
private Renderer _renderer;
private Material[] _materials;
void Awake()
{
_renderer = GetComponent<Renderer>();
// Get a copy of materials to avoid changing shared materials globally
_materials = _renderer.materials;
}
/// <summary>
/// Adjust the smoothness of all materials on this prefab.
/// Smoothness should be clamped between 0 and 1.
/// </summary>
/// <param name="smoothness">Value between 0 (rough) and 1 (smooth).</param>
public void SetSmoothness(float smoothness)
{
smoothness = Mathf.Clamp01(smoothness);
foreach (var mat in _materials)
{
if (mat.HasProperty("_Glossiness"))
{
mat.SetFloat("_Glossiness", smoothness);
}
}
// Assign modified materials back to the renderer so changes take effect
_renderer.materials = _materials;
}
}
How to use:
via the inspector.
User
Use a UI Slider connected to the SmoothnessUIManager or your UI manager.
how exactly
Assistant
Great! Let me give you a step-by-step guide on how to connect a UI Slider to your SmoothnessUIManager so that it controls the smoothness of the selected prefab instance.
Step-by-Step Guide: Connect UI Slider to SmoothnessUIManager
1. Create the Smoothness Slider in the UI
In your Unity Editor:
Right-click in the Hierarchy → UI → Slider
(This will make a slider with a handle and fill).
Select the Canvas object (created automatically if you don’t have one).
Rename the slider something like SmoothnessSlider.
Select the new Slider GameObject.
In the Inspector for the Slider component:
Set Min Value to 0
Set Max Value to 1
Set Value to some starting smoothness, say 0.5
You may also want to customize the slider’s visual aspect (fill colors, etc.).
2. Create a GameObject to hold the SmoothnessUIManager
Create an empty GameObject in the scene (right-click Hierarchy → Create Empty).
Rename it e.g. SmoothnessUIManager.
Attach the SmoothnessUIManager script (from previous example) to it.
3. Assign the Slider to the SmoothnessUIManager
Select the SmoothnessUIManager GameObject.
In the Inspector, you will see the exposed public field smoothnessSlider.
Drag the SmoothnessSlider UI GameObject from the Hierarchy into this field.
4. Link Slider’s OnValueChanged Event to SmoothnessUIManager
Select the SmoothnessSlider in the hierarchy.
In the Inspector → Scroll to the bottom On Value Changed (float) event.
Click the ’+’ button to add a new event listener.
Drag the SmoothnessUIManager GameObject into the object field.
In the dropdown to the right, select the function:
code
SmoothnessUIManager -> UpdateSmoothness (float)
The method will be called every time the slider’s value changes.
User
can you adjust the smoothness script so that I just add it to the prefab without another script?
Assistant
Absolutely! I’ll adjust the PrefabSmoothness script so that you can:
Attach only this script to your prefab.
It will find a singleton slider in your scene by name (or assign it via inspector).
It will automatically subscribe to slider value changes when the prefab is instantiated.
When the prefab is destroyed, it unsubscribes to clean up.
It will update the slider’s value to the current smoothness on start.
You can select multiple prefab instances — each prefab controls the same slider but only one instance’s slider adjustment works at a time (because slider events will trigger all; so we’ll add a simple way to activate/deactivate the prefab’s slider control).
Here’s the full single script to attach to the prefab:
csharp
User
do a different approach, and use this: the prefab with tag "material" should be affected whenever I adjust the smoothness slider in the Ui. Show the whole fixed script
Assistant
Understood! You want a script that does not live on the prefab, but instead a central controller script somewhere in your scene that:
Listens to the UI Smoothness slider changes.
Finds all active GameObjects in the scene with tag "material".
Adjusts the smoothness (_Glossiness) on their materials accordingly.
This way, any prefab instance tagged "material" automatically reacts to the slider without needing to individually scripted behaviors.
Here's the full, self-contained script you can attach to a GameObject in your scene (e.g., an empty GameObject named SmoothnessController) :
csharp
User
readjust it instead of Target Tag "material" it should have Target Layer "material"
Assistant
Sure! Here’s the updated script that uses a Layer instead of a Tag to find the objects to update.
What changed:
Instead of targetTag we now have an integer targetLayer.
The script finds all active renderers in the scene, then filters them by layer.
Only objects on the specified Layer named "material" (or whichever you assign) will have their material smoothness adjusted.
Since Unity doesn’t provide a direct API to find all GameObjects by layer, we’ll use FindObjectsOfType<Renderer>() and filter by layer.
Full updated SmoothnessController.cs script:
csharp
User
it works, but currently its either smooth or not smooth at all when I move the slider - just like on and off, but I want to have it like this: when the slider is all at the left it should not be smooth at all, when the slider is all at the right, it should be totally smooth and inbetween it should adjust according to the sliders position. Fix the script and show all of it
Assistant
The behavior you describe — smoothness "on or off" instead of a continuous range — usually happens because:
The shader _Glossiness property is getting set but the shader uses a different property for smoothness.
Or, the material’s setup restricts smoothness in practice (e.g., metallic workflow).
Or, slider values don’t map correctly to the shader smoothness range.
In Unity's Standard Shader, smoothness corresponds to _Glossiness property, and it should smoothly vary from 0 to 1.
Assuming your materials do support smoothness through _Glossiness, the script works fine.
Possible fix ideas:
Confirm slider Min = 0 and Max = 1 → so value is truly continuous [0..1].
Clamp value in the script (already done).
VERY IMPORTANT: Check if the shader supports _GlossMapScale or uses metallic workflow, in which case _Glossiness can sometimes be overridden.
Additionally, Unity's Standard Shader smoothness may be controlled by _Glossiness, but if the material’s shader is set to “Specular Setup” or uses metallic textures, smoothness can be masked.
But since the question focuses on the script side, I’ll make sure the slider value is passed exactly as float as is, with no approximation or int conversion.
Here’s the full fixed script ensuring the slider value passes through smoothly and updates the materials accordingly.
csharp
User
i use metallic alpha and the slider value is from 1 - 10
it still is either smooth or not. Fix it
Assistant
Thanks for sharing the details! Since:
You’re using metallic-alpha workflow.
Your slider range is from 1 to 10 instead of 0 to 1.
Two things to fix:
The smoothness (_Glossiness) always expects a value between 0 and 1, so you need to convert slider values (1-10) into the 0-1 range properly.
The alpha channel of the metallic map drives smoothness when using metallic workflow, so just setting _Glossiness might not produce smooth results depending on the texture you use.
How to fix your script:
Map slider input from 1-10 → 0-1 float range before applying.
If your metallic map alpha is restricting smoothness, you can multiply your smoothness value by a factor or directly set the _Glossiness to modulate intensity.
Make sure the shader you use supports _Glossiness and the metallic workflow.
Here's the full updated script considering your slider values are 1-10:
csharp
User
it works when the prefab is placed in the scene, but i instantiate my prefabs at runtime and I cant add the slider to the inspector in my prefabs. Fix the script and show all
Assistant
Got it! Since you instantiate prefabs at runtime and cannot assign the slider reference on the prefab prefab itself, you need a central manager/script in the scene (e.g., SmoothnessController) that:
Holds the slider reference.
Controls all objects on the target layer, including ones instantiated later.
Listens to the slider’s onValueChanged event.
Updates smoothness on all current and future objects in that layer.
The main idea:
The manager finds the slider once and listens to changes.
On each slider change it updates all objects on the layer at that moment.
When you instantiate prefabs at runtime, just assign their layer to the target layer (e.g., "material").
The script will automatically find and update those objects, no need to modify the prefab or assign references.
Here's the full fixed, self-contained manager script, to put on any active GameObject in your scene (e.g., an empty SmoothnessController object):
csharp
User
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Crosstales.FB;
using System.IO;
using Newtonsoft.Json;
namespace Kaktusz.SaveSystem
{
public class SaveManager : MonoBehaviour
{
public static SaveManager instance;
code
Assistant
Certainly! To store the slider position in your save system, you'll need to:
Add a field/property in your SaveData class to store the slider value.
Update the slider value in saveData before saving.
Restore the slider value when loading.
You'll likely need a reference to your slider to update its value on load.
Assuming SaveData is a class you can modify (not shown here), you have to:
Add a public float sliderSmoothness = defaultValue; (or similar).
Save it from your slider component.
Load it back to slider.
Since you asked to only modify your SaveManager without removing anything, I will:
Expose a public Slider field in SaveManager to assign the slider.
Before saving, update saveData.sliderSmoothness from smoothnessSlider.value.
When loading, after LoadIntoScene(), update the slider's value.
If you want, you can also store it via PlayerPrefs or inject via events, but this is the most direct way.
Here is your entire modified SaveManager script with the new slider save/load integration added only (with comments so you can see where I added code):
csharp
User
here is my savedata script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Kaktusz.SaveSystem
{
public abstract class ISavable : MonoBehaviour //using an abstract class instead of an actual interface to enforce MonoBehaviour inheritance. For all intents and purposes this is an interface.
{
public abstract IObjectSaveData ToSaveData();
code
Assistant
Certainly! I'll integrate a sliderSmoothness field into your SaveData class and ensure it serializes properly, while leaving all existing code and comments intact. Since SaveData is marked [System.Serializable] and used with JSON.NET, adding a float field will automatically be serialized/deserialized.
I'll:
Add public float sliderSmoothness = 1f; to SaveData.
No other changes required here since the save/load logic in your SaveManager already sets and uses this field.
Here is your full updated SaveData script with the new field added:
csharp
Not yet included in a published release.
Attach this script to your prefab
In your UI manager script, keep a reference to the currently selected prefab instance (with the PrefabSmoothness component).
Hook your UI slider’s OnValueChanged(float) event to call the prefab’s SetSmoothness(float) method.
Example UI Manager snippet that controls smoothness on the selected prefab:
csharp
using UnityEngine;
using UnityEngine.UI;
public class SmoothnessUIManager : MonoBehaviour
{
public Slider smoothnessSlider;
private PrefabSmoothness selectedPrefabSmoothness;
void Start()
{
if (smoothnessSlider != null)
{
// Setup slider callback
smoothnessSlider.onValueChanged.AddListener(UpdateSmoothness);
}
}
// Call this method when the user selects a prefab in your UI/game
public void SetSelectedPrefab(GameObject prefabInstance)
{
selectedPrefabSmoothness = prefabInstance.GetComponent<PrefabSmoothness>();
if (selectedPrefabSmoothness != null)
{
// Optionally initialize slider to current smoothness value (assume 0-1)
float currentSmoothness = 0f;
if (selectedPrefabSmoothness.GetComponent<Renderer>().material.HasProperty("_Glossiness"))
{
currentSmoothness = selectedPrefabSmoothness.GetComponent<Renderer>().material.GetFloat("_Glossiness");
}
smoothnessSlider.value = currentSmoothness;
smoothnessSlider.interactable = true;
}
else
{
smoothnessSlider.interactable = false;
}
}
private void UpdateSmoothness(float value)
{
if (selectedPrefabSmoothness != null)
{
selectedPrefabSmoothness.SetSmoothness(value);
}
}
}
Summary:
Attach PrefabSmoothness script to the prefab to enable smoothness adjustment.
Use a UI Slider connected to the SmoothnessUIManager or your UI manager.
Whenever user selects a prefab, call SetSelectedPrefab(prefabInstance) to update which prefab the slider affects.
Let me know if you want me to help with the UI slider setup or the prefab selection logic!
UpdateSmoothness(float)
5. Prefabs with PrefabSmoothness Script
Ensure your prefab has the PrefabSmoothness script attached. When you select/instantiate your prefab at runtime, call:
public SmoothnessUIManager smoothnessUIManager;
public void OnUserSelectsPrefab(GameObject prefabInstance)
{
smoothnessUIManager.SetSelectedPrefab(prefabInstance);
}
6. Test
Run your game.
Select or instantiate a prefab with the PrefabSmoothness script.
Call SetSelectedPrefab() passing the instance.
The slider will update to show current smoothness.
Moving the slider will call SetSmoothness() on the prefab’s material and visually update smoothness in real time.
You can also add labels/text to the UI to show smoothness value.
If you want, I can help you with a full minimal Unity scene setup, or example prefabs/scripts for testing! Just ask.
using UnityEngine;
using UnityEngine.UI;
[RequireComponent(typeof(Renderer))]
public class PrefabSmoothness : MonoBehaviour
{
// Name of the UI slider in the scene
[Tooltip("Name of the Slider GameObject in the scene.")]
public string sliderObjectName = "SmoothnessSlider";
private Slider smoothnessSlider;
private Renderer _renderer;
private Material[] _materials;
// Is this prefab instance currently "active" to respond to slider changes?
private bool isActive = false;
void Awake()
{
_renderer = GetComponent<Renderer>();
// Get a copy of materials so we're not modifying shared materials
_materials = _renderer.materials;
FindSlider();
}
void OnEnable()
{
// Subscribe to slider updates only if this prefab instance is active
if (smoothnessSlider != null && isActive)
{
smoothnessSlider.onValueChanged.AddListener(OnSliderValueChanged);
}
}
void OnDisable()
{
if (smoothnessSlider != null)
{
smoothnessSlider.onValueChanged.RemoveListener(OnSliderValueChanged);
}
}
void Start()
{
// Initialize slider value to current smoothness
float currentSmoothness = GetCurrentSmoothness();
if (smoothnessSlider != null)
{
smoothnessSlider.value = currentSmoothness;
}
}
// Call this method to make this prefab instance active for slider control
public void Activate()
{
if (smoothnessSlider == null)
{
FindSlider();
if (smoothnessSlider == null)
{
Debug.LogWarning("SmoothnessSlider not found in scene.");
return;
}
}
if (!isActive)
{
isActive = true;
smoothnessSlider.onValueChanged.AddListener(OnSliderValueChanged);
// Update slider to current smoothness of this prefab when activated
smoothnessSlider.value = GetCurrentSmoothness();
}
}
// Call this method to disable this prefab instance's control over the slider
public void Deactivate()
{
if (isActive && smoothnessSlider != null)
{
smoothnessSlider.onValueChanged.RemoveListener(OnSliderValueChanged);
isActive = false;
}
}
private void FindSlider()
{
GameObject sliderObj = GameObject.Find(sliderObjectName);
if (sliderObj != null)
{
smoothnessSlider = sliderObj.GetComponent<Slider>();
if (smoothnessSlider == null)
{
Debug.LogWarning($"GameObject '{sliderObjectName}' does not have a Slider component.");
}
}
else
{
Debug.LogWarning($"Smoothness slider GameObject named '{sliderObjectName}' not found in scene.");
}
}
private float GetCurrentSmoothness()
{
// Return smoothness of first material that has _Glossiness, else 0
foreach (var mat in _materials)
{
if (mat.HasProperty("_Glossiness"))
{
return mat.GetFloat("_Glossiness");
}
}
return 0f;
}
// Called when slider value changes - update all materials smoothness here
public void OnSliderValueChanged(float value)
{
SetSmoothness(value);
}
/// <summary>
/// Adjust the smoothness of all materials on this prefab.
/// </summary>
/// <param name="smoothness">Value between 0 (rough) and 1 (smooth).</param>
public void SetSmoothness(float smoothness)
{
smoothness = Mathf.Clamp01(smoothness);
bool changed = false;
foreach (var mat in _materials)
{
if (mat.HasProperty("_Glossiness"))
{
mat.SetFloat("_Glossiness", smoothness);
changed = true;
}
}
if (changed)
{
_renderer.materials = _materials;
}
}
}
How to use this script:
Attach this script directly to your prefab.
Make sure your scene has a UI Slider named exactly SmoothnessSlider (or change sliderObjectName in the inspector).
When you instantiate or enable the prefab, call Activate() on the prefab instance:
Example:
csharp
GameObject instance = Instantiate(yourPrefab);
PrefabSmoothness ps = instance.GetComponent<PrefabSmoothness>();
ps.Activate(); // to connect prefab with slider events
If you select a different prefab instance later (you can have multiple instances with this script), call Deactivate() on the old instance, then Activate() on the new one to switch the slider control.
Important notes:
This script assumes only one prefab instance is actively controlling the slider at a time.
You control which prefab is active by calling Activate() on that instance and Deactivate() on others.
The slider updates in real-time the materials of the active prefab.
If you want a quick helper example for selecting prefabs:
csharp
public class PrefabSelectionManager : MonoBehaviour
{
private PrefabSmoothness currentActive;
public void SelectPrefab(PrefabSmoothness newActive)
{
if (currentActive != null)
{
currentActive.Deactivate();
}
currentActive = newActive;
if (currentActive != null)
{
currentActive.Activate();
}
}
}
You then call SelectPrefab() passing the prefab instance you want the slider to control.
If you want me, I can also provide you a little example scene configuration or a UI slider prefab! Just ask.
using UnityEngine;
using UnityEngine.UI;
public class SmoothnessController : MonoBehaviour
{
[Tooltip("UI Slider that controls smoothness (0-1)")]
public Slider smoothnessSlider;
[Tooltip("Tag of objects whose materials will be updated")]
public string targetTag = "material";
void Start()
{
if (smoothnessSlider == null)
{
Debug.LogError("Smoothness slider not assigned.");
return;
}
// Subscribe to slider changes
smoothnessSlider.onValueChanged.AddListener(OnSliderValueChanged);
// Optionally initialize materials to current slider value at start
UpdateAllMaterials(smoothnessSlider.value);
}
void OnDestroy()
{
if (smoothnessSlider != null)
{
smoothnessSlider.onValueChanged.RemoveListener(OnSliderValueChanged);
}
}
/// <summary>
/// Called when the slider value changes.
/// </summary>
/// <param name="value">Value 0-1 slider reports.</param>
private void OnSliderValueChanged(float value)
{
UpdateAllMaterials(value);
}
/// <summary>
/// Finds all active GameObjects with the targetTag and updates their material smoothness.
/// </summary>
/// <param name="smoothness">Smoothness value 0-1.</param>
private void UpdateAllMaterials(float smoothness)
{
GameObject[] taggedObjects = GameObject.FindGameObjectsWithTag(targetTag);
foreach (GameObject go in taggedObjects)
{
Renderer rend = go.GetComponent<Renderer>();
if (rend == null)
continue;
// Make sure to get a copy of materials to avoid changing shared materials globally!
Material[] mats = rend.materials;
bool updated = false;
foreach (Material mat in mats)
{
if (mat.HasProperty("_Glossiness"))
{
mat.SetFloat("_Glossiness", smoothness);
updated = true;
}
}
if (updated)
{
// Assign materials back to renderer so changes take effect
rend.materials = mats;
}
}
}
}
How to use this:
Tag your prefab(s) with the tag "material":
Select your prefab in Project or instantiated instances.
In the Inspector set the Tag dropdown to "material" (create that tag if missing).
Create a UI Slider:
In your Canvas, create a Slider (GameObject > UI > Slider).
Set Min = 0, Max = 1, default Value as you want.
Name it e.g. SmoothnessSlider.
Create an empty GameObject and attach the script:
Right-click in Hierarchy → Create Empty.
Rename it e.g. SmoothnessController.
Attach the SmoothnessController script.
Assign the slider to the script:
Select SmoothnessController.
Drag the SmoothnessSlider from your Canvas to the public smoothnessSlider field in the inspector.
Run the scene and adjust the slider:
All GameObjects tagged "material" with a Renderer and a material supporting _Glossiness will update smoothness in real-time.
Why is this approach good:
You only need one controller script for all objects.
No need to attach scripts to individual prefabs.
Works on any objects tagged "material" in the scene — great for dynamically spawned objects.
Easy to maintain and extend (e.g., support other material properties or multiple sliders).
If you want, I can help with the UI slider setup or a sample prefab/material configuration!
using UnityEngine;
using UnityEngine.UI;
public class SmoothnessController : MonoBehaviour
{
[Tooltip("UI Slider that controls smoothness (0-1)")]
public Slider smoothnessSlider;
[Tooltip("Name of the layer of objects whose materials will be updated")]
public string targetLayerName = "material";
private int targetLayer;
void Start()
{
if (smoothnessSlider == null)
{
Debug.LogError("Smoothness slider not assigned.");
return;
}
targetLayer = LayerMask.NameToLayer(targetLayerName);
if (targetLayer == -1)
{
Debug.LogError($"Layer '{targetLayerName}' does not exist. Please add it in the Tags & Layers manager.");
return;
}
// Subscribe to slider changes
smoothnessSlider.onValueChanged.AddListener(OnSliderValueChanged);
// Initialize materials to current slider value at start
UpdateAllMaterials(smoothnessSlider.value);
}
void OnDestroy()
{
if (smoothnessSlider != null)
{
smoothnessSlider.onValueChanged.RemoveListener(OnSliderValueChanged);
}
}
private void OnSliderValueChanged(float value)
{
UpdateAllMaterials(value);
}
/// <summary>
/// Finds all Renderers on objects with targetLayer and updates their materials' smoothness.
/// </summary>
/// <param name="smoothness">Smoothness value 0-1.</param>
private void UpdateAllMaterials(float smoothness)
{
// Find all renderers in scene
Renderer[] allRenderers = FindObjectsOfType<Renderer>();
foreach (Renderer rend in allRenderers)
{
// Check layer of the GameObject
if (rend.gameObject.layer != targetLayer)
continue;
// Work on the materials array (copies, safe to modify)
Material[] mats = rend.materials;
bool updated = false;
foreach (Material mat in mats)
{
if (mat.HasProperty("_Glossiness"))
{
mat.SetFloat("_Glossiness", smoothness);
updated = true;
}
}
if (updated)
{
// Assign back to renderer to apply changes
rend.materials = mats;
}
}
}
}
How to use:
Create or find the Layer named "material" in Edit > Project Settings > Tags and Layers > Layers.
Assign your prefab(s) or GameObjects to that layer:
Select the GameObject or prefab in the Inspector.
Set the Layer dropdown to the material layer.
Create a UI Slider, then assign that slider to the public smoothnessSlider field on your SmoothnessController GameObject.
Run your scene and adjusting the slider will update all GameObjects on layer "material".
If you want me to provide a version that caches renderers for better runtime performance or supports dynamic spawning — just ask!
using UnityEngine;
using UnityEngine.UI;
public class SmoothnessController : MonoBehaviour
{
[Tooltip("UI Slider that controls smoothness (0-1)")]
public Slider smoothnessSlider;
[Tooltip("Name of the layer of objects whose materials will be updated")]
public string targetLayerName = "material";
private int targetLayer;
void Start()
{
if (smoothnessSlider == null)
{
Debug.LogError("Smoothness slider not assigned.");
enabled = false;
return;
}
targetLayer = LayerMask.NameToLayer(targetLayerName);
if (targetLayer == -1)
{
Debug.LogError($"Layer '{targetLayerName}' does not exist.");
enabled = false;
return;
}
// Subscribe to slider changes
smoothnessSlider.onValueChanged.AddListener(OnSliderValueChanged);
// Initialize materials with slider's current value
UpdateAllMaterials(smoothnessSlider.value);
}
void OnDestroy()
{
if (smoothnessSlider != null)
{
smoothnessSlider.onValueChanged.RemoveListener(OnSliderValueChanged);
}
}
private void OnSliderValueChanged(float value)
{
// Directly pass the slider value (which should be between 0 and 1) without any rounding.
UpdateAllMaterials(value);
}
/// <summary>
/// Updates smoothness of all materials on objects in the target layer.
/// </summary>
/// <param name="smoothness">Smoothness between 0 (rough) and 1 (fully smooth).</param>
private void UpdateAllMaterials(float smoothness)
{
// Clamp just in case, though slider should already be clamping.
smoothness = Mathf.Clamp01(smoothness);
Renderer[] allRenderers = FindObjectsOfType<Renderer>();
foreach (Renderer rend in allRenderers)
{
if (rend.gameObject.layer != targetLayer)
continue;
// Copy materials to avoid changing shared ones
Material[] mats = rend.materials;
bool updated = false;
foreach (Material mat in mats)
{
if (mat.HasProperty("_Glossiness"))
{
mat.SetFloat("_Glossiness", smoothness);
updated = true;
}
}
if (updated)
{
// Assign materials back to renderer to apply changes
rend.materials = mats;
}
}
}
}
Also double-check your slider in the Editor:
Select your slider.
Min Value = 0
Max Value = 1
Whole Numbers should be unchecked (so the slider can provide smooth float values, not just 0 or 1).
Default Value can be anything in between.
Summary:
The script already passes the exact slider float value.
The slider must be configured to give smooth floats (not whole numbers).
The materials need to use a shader that supports _Glossiness properly.
With this setup, the smoothness should smoothly interpolate from rough (0) to smooth (1) as you slide.
If you are still seeing the abrupt jump — inspect your material or shader setup!
Let me know if you want help troubleshooting any shader/material setup!
using UnityEngine;
using UnityEngine.UI;
public class SmoothnessController : MonoBehaviour
{
[Tooltip("UI Slider that controls smoothness (1-10)")]
public Slider smoothnessSlider;
[Tooltip("Name of the layer of objects whose materials will be updated")]
public string targetLayerName = "material";
private int targetLayer;
void Start()
{
if (smoothnessSlider == null)
{
Debug.LogError("Smoothness slider not assigned.");
enabled = false;
return;
}
targetLayer = LayerMask.NameToLayer(targetLayerName);
if (targetLayer == -1)
{
Debug.LogError($"Layer '{targetLayerName}' does not exist.");
enabled = false;
return;
}
// Subscribe to slider changes
smoothnessSlider.onValueChanged.AddListener(OnSliderValueChanged);
// Initialize materials with initial slider value
OnSliderValueChanged(smoothnessSlider.value);
}
void OnDestroy()
{
if (smoothnessSlider != null)
{
smoothnessSlider.onValueChanged.RemoveListener(OnSliderValueChanged);
}
}
private void OnSliderValueChanged(float sliderValue)
{
// Convert slider 1-10 → 0-1 smoothly
float smoothness01 = Mathf.InverseLerp(1f, 10f, sliderValue);
UpdateAllMaterials(smoothness01);
}
/// <summary>
/// Updates smoothness of all materials on objects in the target layer.
/// </summary>
/// <param name="smoothness">Smoothness between 0 (rough) and 1 (fully smooth)</param>
private void UpdateAllMaterials(float smoothness)
{
// Clamp to 0-1 just in case
smoothness = Mathf.Clamp01(smoothness);
Renderer[] allRenderers = FindObjectsOfType<Renderer>();
foreach (Renderer rend in allRenderers)
{
if (rend.gameObject.layer != targetLayer)
continue;
Material[] mats = rend.materials;
bool updated = false;
foreach (Material mat in mats)
{
if (mat.HasProperty("_Glossiness"))
{
// Optionally multiply smoothness here if the metallic alpha lowers effect
// e.g. smoothness = Mathf.Clamp01(smoothness * 1.0f);
mat.SetFloat("_Glossiness", smoothness);
updated = true;
}
}
if (updated)
{
rend.materials = mats;
}
}
}
}
What to check in Unity Editor:
Your slider min = 1, max = 10
Whole Numbers unchecked if you want smooth control
This maps the slider’s 1–10 value into 0–1, which is the expected _Glossiness range.
Additional notes:
If smoothness variation is still subtle due to your metallic texture alpha channel, consider adjusting or removing the metallic alpha, or drive a different property.
You can also experiment by multiplying smoothness by a factor greater than 1 inside UpdateAllMaterials() if needed:
Let me know if you want guidance on the metallic alpha textures or a more advanced setup with custom shaders!
using UnityEngine;
using UnityEngine.UI;
public class SmoothnessController : MonoBehaviour
{
[Tooltip("UI Slider that controls smoothness (1-10)")]
public Slider smoothnessSlider;
[Tooltip("Name of the layer of objects whose materials will be updated")]
public string targetLayerName = "material";
private int targetLayer;
void Start()
{
if (smoothnessSlider == null)
{
Debug.LogError("Smoothness slider not assigned in inspector.");
enabled = false;
return;
}
targetLayer = LayerMask.NameToLayer(targetLayerName);
if (targetLayer == -1)
{
Debug.LogError($"Layer '{targetLayerName}' does not exist. Please add it in Tags & Layers.");
enabled = false;
return;
}
// Subscribe to slider changes
smoothnessSlider.onValueChanged.AddListener(OnSliderValueChanged);
// Initialize all materials at start
OnSliderValueChanged(smoothnessSlider.value);
}
void OnDestroy()
{
if (smoothnessSlider != null)
smoothnessSlider.onValueChanged.RemoveListener(OnSliderValueChanged);
}
private void OnSliderValueChanged(float sliderValue)
{
// Map slider 1-10 range to 0-1 for _Glossiness
float smoothness01 = Mathf.InverseLerp(1f, 10f, sliderValue);
UpdateAllMaterials(smoothness01);
}
/// <summary>
/// Updates smoothness of all materials on objects in target layer.
/// Works for prefabs instantiated at runtime as well.
/// </summary>
/// <param name="smoothness">Value between 0 and 1.</param>
private void UpdateAllMaterials(float smoothness)
{
smoothness = Mathf.Clamp01(smoothness);
Renderer[] allRenderers = FindObjectsOfType<Renderer>();
foreach (Renderer rend in allRenderers)
{
if (rend.gameObject.layer != targetLayer)
continue;
Material[] mats = rend.materials;
bool updated = false;
foreach (Material mat in mats)
{
if (mat.HasProperty("_Glossiness"))
{
mat.SetFloat("_Glossiness", smoothness);
updated = true;
}
}
if (updated)
rend.materials = mats;
}
}
}
How to use this in your runtime setup:
Create a GameObject in the scene (e.g. empty, name it SmoothnessController).
Attach this SmoothnessController script to it.
Assign your UI Slider to the smoothnessSlider field in inspector.
Make sure your prefabs (and instantiated instances) have their Layer set to "material".
On runtime, this controller will update smoothness on all renderers currently in the scene on the "material" layer — including ones instantiated dynamically.
Adjust the slider to modify smoothness smoothly from 0 (slider=1) to 1 (slider=10).
Important:
You only need to assign the slider once on this manager in the scene.
Prefab instances do NOT need any special script or inspector assignment.
Just make sure that your prefab’s root GameObject (or any relevant renderer objects) are set to the correct layer material.
That’s it! This approach scales well for dynamic instantiation, batch updates, and keeps your prefab clean.
If you want, I can help you add a Runtime Event to refresh objects or optimize performance by caching renderers too — just ask!
[Tooltip("This is what file extension save files will use. This doesn't affect the formatting of the data stored inside these files.")]
public string fileExtension = "nt9";
SaveData saveData;
JsonSerializerSettings serialisationSettings = new JsonSerializerSettings();
public System.Action OnNewFileStarted;
private void Awake()
{
instance = this;
serialisationSettings.TypeNameHandling = TypeNameHandling.Auto;
}
private void Start()
{
OpenTemplate();
}
public void SaveButForButtons()
{
Save();
}
public bool Save()
{
if (saveData == null)
saveData = new SaveData();
saveData.SaveAllInScene();
string path = FileBrowser.SaveFile("Save File", string.Empty, "MySaveFile", fileExtension).Replace('\\', '/');
if (string.IsNullOrEmpty(path)) return false;
SaveToFile(saveData, path);
return true;
}
public void SaveAndQuit()
{
Save();
Application.Quit();
}
public void SaveAndNewFile()
{
if (Save())
NewFile();
}
public void SaveAndOpen()
{
if (Save())
Open();
}
//SK EDIT START //
public void SaveAndImport()
{
if (Save())
Import();
}
//SK EDIT END //
public void Open()
{
string path = FileBrowser.OpenSingleFile("Open File", string.Empty, fileExtension).Replace('\\', '/');
if (string.IsNullOrEmpty(path)) return;
saveData = LoadFromFile(path);
saveData.LoadIntoScene();
}
public void OpenTemplate()
{
if (!PlayerPrefs.GetString("FileToLoad", "").Equals(""))
{
saveData = GetDataFromResources(PlayerPrefs.GetString("FileToLoad", ""));
saveData.LoadIntoScene();
PlayerPrefs.SetString("FileToLoad", "");
}
}
SaveData GetDataFromResources(string fileName)
{
System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
stopwatch.Start();
string json = Resources.Load<TextAsset>(fileName).text;
SaveData data = JsonConvert.DeserializeObject<SaveData>(json, serialisationSettings);
stopwatch.Stop();
Debug.Log("Loaded save file (" + data.savedObjects.Count + " objects) in " + stopwatch.ElapsedMilliseconds + "ms");
return data;
}
//SK EDIT START //
public void Import()
{
string path = FileBrowser.OpenSingleFile("Open File", string.Empty, fileExtension).Replace('\\', '/');
if (string.IsNullOrEmpty(path)) return;
saveData = LoadFromFile(path);
saveData.ImportIntoScene();
}
//SK EDIT END //
public void NewFile()
{
SaveData.ClearScene();
OnNewFileStarted?.Invoke();
}
public void SaveToFile(SaveData data, string path)
{
System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
stopwatch.Start();
string json = JsonConvert.SerializeObject(data, serialisationSettings);
File.WriteAllText(path, json);
stopwatch.Stop();
Debug.Log("Saved to disk (" + data.savedObjects.Count + " objects) in " + stopwatch.ElapsedMilliseconds + "ms");
}
public SaveData LoadFromFile(string path)
{
if (!File.Exists(path)) //bad path!
{
Debug.LogError("Tried to load inexistent save file at " + path);
return new SaveData();
}
System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
stopwatch.Start();
string json = File.ReadAllText(path);
SaveData data = JsonConvert.DeserializeObject<SaveData>(json, serialisationSettings);
stopwatch.Stop();
Debug.Log("Loaded save file (" + data.savedObjects.Count + " objects) in " + stopwatch.ElapsedMilliseconds + "ms");
return data;
}
}
}
now lets remember the sliders position whenever the user saves it should save the correctposition of the slider, so when he loads again it should show it. Use this script to integrate that. Do not remove any other code or comments, just input the new feature and show the whole script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Crosstales.FB;
using System.IO;
using Newtonsoft.Json;
using UnityEngine.UI; // Added for Slider
namespace Kaktusz.SaveSystem
{
public class SaveManager : MonoBehaviour
{
public static SaveManager instance;
[Tooltip("This is what file extension save files will use. This doesn't affect the formatting of the data stored inside these files.")]
public string fileExtension = "nt9";
SaveData saveData;
JsonSerializerSettings serialisationSettings = new JsonSerializerSettings();
public System.Action OnNewFileStarted;
// *** NEW: add slider reference to SaveManager to save/load slider value ***
[Tooltip("Assign your Smoothness UI Slider here, so save/load can store its position.")]
public Slider smoothnessSlider;
private void Awake()
{
instance = this;
serialisationSettings.TypeNameHandling = TypeNameHandling.Auto;
}
private void Start()
{
OpenTemplate();
}
public void SaveButForButtons()
{
Save();
}
public bool Save()
{
if (saveData == null)
saveData = new SaveData();
// *** NEW: store slider value before saving ***
if (smoothnessSlider != null)
{
saveData.sliderSmoothness = smoothnessSlider.value;
}
saveData.SaveAllInScene();
string path = FileBrowser.SaveFile("Save File", string.Empty, "MySaveFile", fileExtension).Replace('\\', '/');
if (string.IsNullOrEmpty(path)) return false;
SaveToFile(saveData, path);
return true;
}
public void SaveAndQuit()
{
Save();
Application.Quit();
}
public void SaveAndNewFile()
{
if (Save())
NewFile();
}
public void SaveAndOpen()
{
if (Save())
Open();
}
//SK EDIT START //
public void SaveAndImport()
{
if (Save())
Import();
}
//SK EDIT END //
public void Open()
{
string path = FileBrowser.OpenSingleFile("Open File", string.Empty, fileExtension).Replace('\\', '/');
if (string.IsNullOrEmpty(path)) return;
saveData = LoadFromFile(path);
saveData.LoadIntoScene();
// *** NEW: restore slider value after loading ***
if (smoothnessSlider != null && saveData != null)
{
smoothnessSlider.value = saveData.sliderSmoothness;
}
}
public void OpenTemplate()
{
if (!PlayerPrefs.GetString("FileToLoad", "").Equals(""))
{
saveData = GetDataFromResources(PlayerPrefs.GetString("FileToLoad", ""));
saveData.LoadIntoScene();
PlayerPrefs.SetString("FileToLoad", "");
// *** NEW: restore slider value after loading template ***
if (smoothnessSlider != null && saveData != null)
{
smoothnessSlider.value = saveData.sliderSmoothness;
}
}
}
SaveData GetDataFromResources(string fileName)
{
System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
stopwatch.Start();
string json = Resources.Load<TextAsset>(fileName).text;
SaveData data = JsonConvert.DeserializeObject<SaveData>(json, serialisationSettings);
stopwatch.Stop();
Debug.Log("Loaded save file (" + data.savedObjects.Count + " objects) in " + stopwatch.ElapsedMilliseconds + "ms");
return data;
}
//SK EDIT START //
public void Import()
{
string path = FileBrowser.OpenSingleFile("Open File", string.Empty, fileExtension).Replace('\\', '/');
if (string.IsNullOrEmpty(path)) return;
saveData = LoadFromFile(path);
saveData.ImportIntoScene();
// *** NEW: restore slider value after import ***
if (smoothnessSlider != null && saveData != null)
{
smoothnessSlider.value = saveData.sliderSmoothness;
}
}
//SK EDIT END //
public void NewFile()
{
SaveData.ClearScene();
OnNewFileStarted?.Invoke();
}
public void SaveToFile(SaveData data, string path)
{
System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
stopwatch.Start();
string json = JsonConvert.SerializeObject(data, serialisationSettings);
File.WriteAllText(path, json);
stopwatch.Stop();
Debug.Log("Saved to disk (" + data.savedObjects.Count + " objects) in " + stopwatch.ElapsedMilliseconds + "ms");
}
public SaveData LoadFromFile(string path)
{
if (!File.Exists(path)) //bad path!
{
Debug.LogError("Tried to load inexistent save file at " + path);
return new SaveData();
}
System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
stopwatch.Start();
string json = File.ReadAllText(path);
SaveData data = JsonConvert.DeserializeObject<SaveData>(json, serialisationSettings);
stopwatch.Stop();
Debug.Log("Loaded save file (" + data.savedObjects.Count + " objects) in " + stopwatch.ElapsedMilliseconds + "ms");
return data;
}
}
}
You still need to:
Add public float sliderSmoothness; to your SaveData class:
csharp
// In SaveData.cs:
public class SaveData
{
// ... your existing members
public float sliderSmoothness = 1f; // default starting value matching slider's default
// The rest unchanged...
}
Summary:
The SaveManager now stores slider value inside the SaveData just before saving.
When loading/importing, it sets the slider value back to the saved one.
You must assign the smoothnessSlider UI element to the SaveManager inspector field.
Modify your SaveData class to hold the slider value.
Let me know if you want me to help with SaveData or wiring the slider UI to this!
public virtual bool ShouldSaveIfDisabled() { return false; } //set to true to include in save data even if the gameobject is disabled
}
/// <summary>
/// Data about some object which can be loaded into the scene
/// </summary>
public interface IObjectSaveData
{
void LoadIntoScene();
}
[System.Serializable]
public class SaveData
{
public List<IObjectSaveData> savedObjects = new List<IObjectSaveData>();
/// <summary>
/// Cache of all objects which are part of the scene (not prefabs) that should have persistent information.
/// </summary>
public static SavableSceneObject[] savableSceneObjectsCache;
public void SaveAllInScene()
{
savedObjects.Clear();
ISavable[] savables = MiscUtils.FindObjectsOfTypeIncludingDisabled<ISavable>();
//Debug.Log(savables.Length);
foreach (ISavable savable in savables)
{
if (savable.gameObject.activeSelf == false && !savable.ShouldSaveIfDisabled()) continue; //skip destroyed objects
// Debug.Log(savable.gameObject.name);
savedObjects.Add(savable.ToSaveData());
}
}
/// <summary>
/// Clears scene of any savables and then spawns in ones from this save file
/// </summary>
public void LoadIntoScene()
{
ClearScene(); //clear scene of any previously spawned savables
savableSceneObjectsCache = MiscUtils.FindObjectsOfTypeIncludingDisabled<SavableSceneObject>();
//spawn savables from save
foreach (IObjectSaveData savedObject in savedObjects)
{
savedObject.LoadIntoScene();
}
}
// SK EDIT START //
public void ImportIntoScene()
{
RLD.TagManager.Instance.ClearAllTags();
//ClearScene(); //clear scene of any previously spawned savables
//savableSceneObjectsCache = MiscUtils.FindObjectsOfTypeIncludingDisabled<SavableSceneObject>();
//spawn savables from save
foreach (IObjectSaveData savedObject in savedObjects)
{
savedObject.LoadIntoScene();
}
}
// SK EDIT END //
public static void ClearScene()
{
RLD.TagManager.Instance.ClearAllTags();
//deselect any selected objects
RLD.RTObjectSelection.Get.ClearSelection(false);
RLD.RTObjectSelection.Get.StartCoroutine(DisableSelectionTemporarily());
RLD.RTUndoRedo.Get.ClearActions(); //clear undo/redo history
//clear scene of any previously spawned savables (savable prefabs)
SavablePrefab[] spawnedSavables = GameObject.FindObjectsOfType<SavablePrefab>();
for (int i = 0; i < spawnedSavables.Length; i++)
{
spawnedSavables[i].gameObject.SetActive(false);
GameObject.Destroy(spawnedSavables[i].gameObject);
}
}
public static IEnumerator DisableSelectionTemporarily()
{
RLD.RTObjectSelection.Get.SetEnabled(false);
yield return new WaitForSeconds(0.1f);
RLD.RTObjectSelection.Get.SetEnabled(true);
}
}
}
Integrate it directly here and leave all other code and comments, just input the new feature and show the whole script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Kaktusz.SaveSystem
{
public abstract class ISavable : MonoBehaviour //using an abstract class instead of an actual interface to enforce MonoBehaviour inheritance. For all intents and purposes this is an interface.
{
public abstract IObjectSaveData ToSaveData();
public virtual bool ShouldSaveIfDisabled() { return false; } //set to true to include in save data even if the gameobject is disabled
}
/// <summary>
/// Data about some object which can be loaded into the scene
/// </summary>
public interface IObjectSaveData
{
void LoadIntoScene();
}
[System.Serializable]
public class SaveData
{
public List<IObjectSaveData> savedObjects = new List<IObjectSaveData>();
/// <summary>
/// Stores the slider smoothness value (1-10 range mapped to 0-1 in SaveManager).
/// </summary>
public float sliderSmoothness = 1f; // Default slider value: corresponds to leftmost slider position.
/// <summary>
/// Cache of all objects which are part of the scene (not prefabs) that should have persistent information.
/// </summary>
public static SavableSceneObject[] savableSceneObjectsCache;
public void SaveAllInScene()
{
savedObjects.Clear();
ISavable[] savables = MiscUtils.FindObjectsOfTypeIncludingDisabled<ISavable>();
//Debug.Log(savables.Length);
foreach (ISavable savable in savables)
{
if (savable.gameObject.activeSelf == false && !savable.ShouldSaveIfDisabled()) continue; //skip destroyed objects
// Debug.Log(savable.gameObject.name);
savedObjects.Add(savable.ToSaveData());
}
}
/// <summary>
/// Clears scene of any savables and then spawns in ones from this save file
/// </summary>
public void LoadIntoScene()
{
ClearScene(); //clear scene of any previously spawned savables
savableSceneObjectsCache = MiscUtils.FindObjectsOfTypeIncludingDisabled<SavableSceneObject>();
//spawn savables from save
foreach (IObjectSaveData savedObject in savedObjects)
{
savedObject.LoadIntoScene();
}
}
// SK EDIT START //
public void ImportIntoScene()
{
RLD.TagManager.Instance.ClearAllTags();
//ClearScene(); //clear scene of any previously spawned savables
//savableSceneObjectsCache = MiscUtils.FindObjectsOfTypeIncludingDisabled<SavableSceneObject>();
//spawn savables from save
foreach (IObjectSaveData savedObject in savedObjects)
{
savedObject.LoadIntoScene();
}
}
// SK EDIT END //
public static void ClearScene()
{
RLD.TagManager.Instance.ClearAllTags();
//deselect any selected objects
RLD.RTObjectSelection.Get.ClearSelection(false);
RLD.RTObjectSelection.Get.StartCoroutine(DisableSelectionTemporarily());
RLD.RTUndoRedo.Get.ClearActions(); //clear undo/redo history
//clear scene of any previously spawned savables (savable prefabs)
SavablePrefab[] spawnedSavables = GameObject.FindObjectsOfType<SavablePrefab>();
for (int i = 0; i < spawnedSavables.Length; i++)
{
spawnedSavables[i].gameObject.SetActive(false);
GameObject.Destroy(spawnedSavables[i].gameObject);
}
}
public static IEnumerator DisableSelectionTemporarily()
{
RLD.RTObjectSelection.Get.SetEnabled(false);
yield return new WaitForSeconds(0.1f);
RLD.RTObjectSelection.Get.SetEnabled(true);
}
}
}
Summary:
sliderSmoothness is now part of the serialized save data.
No changes to methods required here.
Your existing SaveManager integration which stores/loads this value will now work seamlessly.
You can continue managing this value as shown previously in your SaveManager script.
If you want me to provide additional guidance on how to integrate this with your UI slider or anything else, just ask!