#Having an `Attribute`, assigned to the
1 messages · Page 1 of 1 (latest)
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.
SerializedProperty.boxedValue doesn't exist
Strange. I cannot access it inside of PropertyDrawer.OnGUI
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
Working from a PropertyDrawer should not make any difference on that matter, this is weird.
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
It still exists in Unity 6, so it being removed is not conceivable. Can you share a bigger sample of your code ?
This is the entire attribute, which only finds methods correctly inside of the MonoBehaviours
C/P your code and I can access boxedValue... it puzzles me even more.
I am using Unity 2021.3.27f1
Well seems like it's a 2022 thing ._. Thought it would be older than that.
Well, yeah, reflection might be your only solution here
I'm not sure, if the Attribute is assigned to the string foo inside of CloudLayer, does boxedValue get foo or its class?
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.
Show code (?) of the attr declaration specifically
yeah, so Editor is only for UnityEngine.Objects, so there's no way to get the actual non-Object just from property
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.
I guess I'll just have to use property.propertyPath to find the object. That's just pretty ugly though
yeah that's the way :p
CloudLayer[] cloudLayers has its type
Thank you both for your help. I appreciate it 🙂
didn't actually get to help but np 😛
You pretty much did everything alone x)