#Having an `Attribute`, assigned to the

1 messages · Page 1 of 1 (latest)

stark pulsar
#

I might be wrong here, but for a PropertyDrawer, you need to access the property's value and not the serializedObject.targetObject. If CloudLayer doesn't derive from neither MonoBehaviour nor ScriptableObject, you may be able to get your CloudLayer with:

CloudLayer cloudLayer = property.boxedValue as CloudLayer;

Make sure to test it is not null before using it and you should be good to go.

burnt folio
burnt folio
#

It only contains values for all SerializedPropertyType, like floatValue, vectorValue, colorValue etc., but I have not been able to find any boxed object while working with drawers

stark pulsar
#

Working from a PropertyDrawer should not make any difference on that matter, this is weird.

burnt folio
#

Yes, I thought that was a SerializedProperty class defined in another namespace first

#

I've tried accessing it from one of my Editors, and it didn't work either

#

I guess reflection is the only thing to use here

stark pulsar
#

It still exists in Unity 6, so it being removed is not conceivable. Can you share a bigger sample of your code ?

burnt folio
#

This is the entire attribute, which only finds methods correctly inside of the MonoBehaviours

stark pulsar
#

C/P your code and I can access boxedValue... it puzzles me even more.

burnt folio
#

I am using Unity 2021.3.27f1

stark pulsar
#

Well seems like it's a 2022 thing ._. Thought it would be older than that.

#

Well, yeah, reflection might be your only solution here

burnt folio
#

I'm not sure, if the Attribute is assigned to the string foo inside of CloudLayer, does boxedValue get foo or its class?

stark pulsar
#

The attribute property would be the variable foo, so boxedValue would return the value of foo, but in the form of an object, meaning you'll have to cast it to a string first. But in the case of a string, you generally use stringValue anyway.

hybrid parcel
#

Show code (?) of the attr declaration specifically

hybrid parcel
#

Field declaration*

#

Where you apply the attribute

burnt folio
#

OnValidate is the attribute

hybrid parcel
#

yeah, so Editor is only for UnityEngine.Objects, so there's no way to get the actual non-Object just from property

stark pulsar
#

That's kinda wrong as it is a property drawer for an attribute here

#

The issue would be to directly get the CloudLayer as a whole, which can be retrieved with boxedValue (with some limitations). The problem here is that even if they wanted to use it, boxedValue is not accessible.
But accessing children values like name or moveDirection should be fine.

burnt folio
#

I guess I'll just have to use property.propertyPath to find the object. That's just pretty ugly though

hybrid parcel
#

yeah that's the way :p

burnt folio
#

CloudLayer[] cloudLayers has its type

#

Thank you both for your help. I appreciate it 🙂

hybrid parcel
#

didn't actually get to help but np 😛

stark pulsar
#

You pretty much did everything alone x)