Question by
wannabuh_unity · Feb 24 at 05:16 PM ·
instantiateinheritancepropertiesscriptable object
How can I automatically update a child ScriptableObject's property values when modifying the parent's instanced property values?
I have a parent SO with a list property that contains Stat structs. I'm initializing this list in an awake function where I add all the stats. The issue I'm facing is when I add a new stat to the parent list, I want that to reflect in the child SOs that I've already created. Is this even possible with ScriptableObjects?
Here are the snippets of code:
Stats.cs
using System;
using System.Collections.Generic;
using UnityEngine;
[Serializable]
public struct Stat
{
[ReadOnlyAttribute] public string name;
public float value;
}
public class Stats : ScriptableObject
{
public List<Stat> attributes;
private void Awake()
{
attributes = new List<Stat>()
{
new Stat { name = Constants.AGILITY, value = 0.0f },
new Stat { name = Constants.STRENGTH, value = 0.0f },
new Stat { name = Constants.STAMINA, value = 0.0f },
new Stat { name = Constants.SPEED, value = 0.0f },
};
}
}
The player stats (Child SO):
If I add a new Stat (let's say intelligence) to the parent SO's list, it won't get added to the child SO list.
capture.png
(16.7 kB)
Comment