- Home /
PropertyDrawer: Texture2D preview not showing up
SerializedProperty sp = property.FindPropertyRelative("springTexture")
sp .objectReferenceValue = EditorGUI.ObjectField(position, "asdf", sp .objectReferenceValue, typeof(Texture2D), false);
I have the code shown above. However when I test it out in the editor, I can assign it a texture (and it opens it when i double click the field) however, the preview doesnt show (as seen below) the image which is really important to me.
(Empty slots show that it is "None" but the ones that are assigned just turn in to blank)
[Edit] It sort of shows up for a fraction of a second when the script gets refreshed, but it disappears right after that.
why would you assign to sp.objectReferenceValue
to what is in your object field? That is what is already stored there… so I guess you just override whatever you put into it to what was in it before -> "None". If you don't want to do anything with the object set in the field, you don't even need to catch its return value.
The code that I have does work. If i assign it a texture and click on the non existing preview, it highlights the refrence in the project folder
I believe the ObjectField does not automatically change the field (just how like floatField works. Of course its different if you pass the serializedProperty it self.). This is why I need to assign it back to the referene Value. If not, the reference never changes