I’ve looked all over but I haven’t found an answer. Say I have an array called MyPrefabs:
public GameObject[] MyPrefabs;
I add the prefabs I want to the array in the inspector. Let’s say I have a Cube object with a CubeScript attached. CubeScript has a speed variable which’s default is 5.
public class CubeScript
{
public int Speed = 5;
}
I save the Cube with the CubeScript attached to a prefab and assign the prefab to the MyPrefabs Array.
I then decide that I want to modify that value.
MyPrefabs[0].GetComponent<CubeScript>().Speed = 10;
So now let’s say I want the default value again. How would I go about doing that? Obviously I could store the Speed variable in a separate variable, but that wouldn’t really be feasible when I have multiple Prefabs each having multiple variables. I thought about copying the MyPrefabs array at Start to an Array called, say, MyPrefabsDefault then assigning MyPrefabs to the MyPrefabsDefault when I wanted to reset it to it’s original values, but I’m not sure how that would work or if it’s the best way.
You forgot one aspect: The speed may not be initialized with 5 in the inspector, but maybe with say 7. Now, he wants to reset this value he needs some sort of backup variable that stored this "inspector set value".
– AdmiralThrawn