I have a ScriptableObject with two fields of a Serializable BattleCreature class, and an array of BattleCreatures, with references to the BattleCreature objects at those fields as well, as shown in this Inspector screenshot:
If I try to edit the fields inside the array elements, they also change their respective field (Creature A is at index 0, Creature B is at index 1) as expected, since they are both referencing the same object. In this image, I edit Element 0’s HP to 123:
However if I try the same from Creature A/B fields, it fails to edit the values. I keep typing 4, Backspace, Delete, nothing changes:
Also, if I remove the element from the array, the field from Creature A becomes editable again:
And Creature B / Former Element 0, now Element 1 seem to have become independent objects (does removing an element from an array of Serializable objects in Inspector cause every other element to be replaced by a copied instance?):
This is the code of the Battle class:
using UnityEngine;
public class Battle : ScriptableObject {
[SerializeField] private BattleCreature creatureA;
[SerializeField] private BattleCreature creatureB;
[SerializeField] private BattleCreature[] battleOrder;
public void SetupBattle(CoreCreature creatureA, CoreCreature creatureB) {
this.creatureA = new BattleCreature(creatureA);
this.creatureB = new BattleCreature(creatureB);
this.battleOrder = new []{
this.creatureA,
this.creatureB
};
}
}
The SetupBattle function is called by a simple GameObject in the scene:
using UnityEngine;
public class BattleController : MonoBehaviour {
[SerializeField] private Battle battle;
[SerializeField] private CoreCreature creatureA;
[SerializeField] private CoreCreature creatureB;
void Start() {
this.battle.SetupBattle(this.creatureA, this.creatureB);
}
}
And this is the BattleCreature code.
using System;
using UnityEngine;
[Serializable]
public class BattleCreature {
[SerializeField, Min(0)] private int hp = 0;
[SerializeField, Min(1)] private int atk = 1;
[SerializeField, Min(1)] private int def = 1;
[SerializeField, Min(1)] private int spd = 1;
private CoreCreature creature;
public BattleCreature(CoreCreature creature) {
this.creature = creature;
this.hp = creature.HP;
this.atk = creature.Atk;
this.def = creature.Def;
this.spd = creature.Spd;
}
}
In short, the bug I am reporting here is that after the object already on a field is added to an serialized array field, I can only ever edit it through that array.




