I’ve seen several posts about how to potentially solve this issue but they all tell me to make the class Non-Serializable.
I have a simple script:
[System.Serializable]
public class Item {
int id;
Inventory inv;
}
[System.Serializable]
public class Inventory{
public List<Item> items;
}
I have this so that players can have bags in their inventories, which also contain items (including other bags) and so on. Obviously I will limit the depth myself but this structure alone throws errors on runtime.
Serialization depth limit exceeded at 'Inventory'. There may be an object composition cycle in one or more of your serialized classes
Is there a way to suppress these errors without making my class Non-Serializable? If not, does anyone have a workaround for what I’m trying to achieve?
I agree, there are many answers to this question and a lot of discussion about it. My take on it is, that your class design can be improved which solves the issue.
A circular reference is the strongest kind of dependency, and you generally want to avoid this. Why does your Item need to know which Inventory it belongs to? If you want to follow Object-Oriented Programming, an Item doesn’t know anything but that it’s an item and what it’s stats are. An item on the floor or in a chess doesn’t have an inventory, also it doesn’t have any container, it only has it’s own properties. The container can manage items and if you need to lookup where something belongs you can do this via the Inventory class.
So that’s how I would avoid the serialization issue. Post more code if you want to try it and need more help. 
When unity serialization occurs, unity will serialize a default value. So unity is warning you that “Item”, is serializing a new default “Inventory” which is then serializing a new default “Item”, serializing a new “Inventory”, continuing on infinitely until the depth limit is reached.
I would suggest not allowing players to put a bag with items into other bags (why do this anyway?). For example, WoW has bag slots on the player which are different from the bags in the inventory slot.
One way around is to have an Inventory contain a List. Then you can use that id as a key to the item. You identify what items are in an inventory by it’s id instead of reference. I don’t know if your items have unique ids or if the ids are types of items