jknightdoeswork / swatchr

A color palette management system for Unity
MIT License
110 stars 15 forks source link

InvalidCastException when creating an array or list of SwatchrColor #2

Closed haywirephoenix closed 5 years ago

haywirephoenix commented 5 years ago

Thanks for swatchr it's awesome. I'm having fun expanding it to work with UI elements. I'm trying to build a runtime color switcher that can toggle between swatches. This error appears when trying to create a list (or array) of swatches, I think the Custom Editor fails because the list is initially empty before you add items. I've tried modifying this line to check if it's null first but it didn't work.

SwatchrColorDrawer.cs line 19

SwatchrColor swatchrColor =(SwatchrColor)fieldInfo.GetValue(property.serializedObject.targetObject);

Using generic scriptableobject list works, but then I cannot cast back to a swatchrcolor.

haywirephoenix commented 5 years ago

Use Swatch instead of SwatchrColor!

jknightdoeswork commented 5 years ago

Hey! Thanks for the positive feedback!

So you figured this out? It wasn't a swatchr bug?

haywirephoenix commented 5 years ago

I found a workaround, thanks!

You could call it a bug depending on how you want to use it. I think it's to do with the custom inspector SwatchrColorDrawer.cs as it's not built to expect a null input, or display multiple times? As long as you use "Swatch" in lists or arrays instead of "SwatchrColor", it works just fine. But you won't see the color pallete in the inspector, they just look like standard scriptableobjects. It wouldn't be too difficult to build a custom inspector for this but in my case it's not needed.

It seems ReplaceSelfWithOtherSwatch expects a Swatch anyway, rather than a SwatchrColor. So saves me figuring out how to convert it back, maybe swatchrColor._swatch