public static void SaveAgentObject(JsonWriter writer, RTSAgent agent) { if (writer == null || agent == null) { return; } writer.WriteStartObject(); agent.SaveDetails(writer); Ability[] abilities = agent.GetComponents <Ability>(); foreach (Ability ability in abilities) { ability.SaveDetails(writer); } writer.WriteEndObject(); }