I’m using a custom scriptableObject “PropPlacementData” to hold position, rotation and scale data for a procedural generation tool I am building. This transform data is being held in a custom class called “HelperMatrix.”
The problem is that when I quit the program and reopen it, instances of PropPlacementData remember that they have been instantiated (see bool HasBeenInstantiated below), remember the size of the HelperMatrix array, but not the contents of the HelperMatrix instances.
public class PropPlacementData : ScriptableObject {
public List<HelperMatrix> SmallPropTransforms { get; private set; }
public List<HelperMatrix> MediumPropTransforms { get; private set; }
public List<HelperMatrix> LargePropTransforms { get; private set; }
public bool HasBeenInstantiated = false;
public void SetPropTransforms(List<GameObject> allProps)
{
if (!HasBeenInstantiated)
{
SmallPropTransforms = new List<HelperMatrix>();
MediumPropTransforms = new List<HelperMatrix>();
LargePropTransforms = new List<HelperMatrix>();
Debug.Log("Created new Prop Placement Data");
HasBeenInstantiated = true;
}
foreach (var prop in allProps)
{
var helperMatrix = new HelperMatrix(prop.transform);
switch (prop.tag)
{
case "Prop Small": SmallPropTransforms.Add(helperMatrix); break;
case "Prop Medium": MediumPropTransforms.Add(helperMatrix); break;
case "Prop Large": LargePropTransforms.Add(helperMatrix); break;
default: MediumPropTransforms.Add(helperMatrix); break;
}
}
EditorUtility.SetDirty(this);
Debug.Log("Set Prop placement data as dirty");
}
}
[System.Serializable]
public class HelperMatrix
{
public Vector3 Position; //{ get; set; }
public Quaternion Rotation; //{ get; private set; }
public Vector3 Scale; //{ get; private set; }
public HelperMatrix(Transform transform)
{
Position = new Vector3(transform.localPosition.x, transform.localPosition.y, transform.localPosition.z);
Rotation = new Quaternion(transform.localRotation.x, transform.localRotation.y, transform.localRotation.z, transform.localRotation.w);
Scale = new Vector3(transform.localScale.x, transform.localScale.y, transform.localScale.z);
}
}
These classes are part of a larger structure but hopefully these classes are enough to highlight where the problem might be. I’ve been working with custom editors for a while now and have many that are working fine, so I’m a bit lost about what is happening here because I can’t see that I’m doing anything differently.
Any guidance would be helpful!