After running the following loop (one iteration), battleshipParts.Count
returns 2.
The code is ran once in the ScriptableObject.Awake
for (byte i = 0; i < 1; i++)
{
var battleshipPart = CreateInstance<BattleshipPart>();
battleshipPart.battleshipData = this;
battleshipParts.Add(battleshipPart);
}
I tried using the debugger and walking through the code, after the execution of
battleshipPart.battleshipData = this;
battleshipParts.Count
is already 1
battleshipPart.battleshipData
is used to hold a reference to its battleship parent. Implementation:
public class BattleshipPart : ScriptableObject
{
public Vector2 gridPosition;
public BattleshipData battleshipData;
public bool isHit = false;
}
The battleshipParts
list isn't modified anywhere else besides this code. Besides. Why would it update itself with a null
value after running battleshipPart.battleshipData = this;
?