#Poco inside array getting created by viewing object

1 messages · Page 1 of 1 (latest)

alpine arch
#

I have an inventory in my game which currently is an array of items, a serializable plain c# class. Checking if there's a free spot in the inventory loops through the array and compares array[i] == null. This works until I clicked on the gameObject to view the array in inspector. I forgot the inspector creates the Item instead of letting it be null, and it uses the default ctor. this leads to a few logic errors.

Is there any simple way I can still view my list of items in inspector but allow elements to be null? I'm wondering if theres a common workaround for this sort of thing since id rather not change the Item logic purely for viewing it in inspector.

This is a small example to reproduce this with. https://paste.mod.gg/kpuyveeycssy/0. The logs will change from 10 being null to 0 as soon as you click the object to see it in inspector

trail helm
#

Pretty sure you just want [SerializeReference] on MyPoco[] right?

#

Or does that not apply to the things inside the collection

alpine arch
#

it works, thanks

trail helm
#

😄

I don't know the smartypants explanation of it but afaik it works similar to properties where it explicitly treats that field like its pointing to something rather than storing something directly