Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ReadOnly] does not work on ScriptableObjects in NaughtyAttributes 2.x, used to in 1.x. #113

Closed
KesKim opened this issue Feb 4, 2020 · 10 comments

Comments

@KesKim
Copy link

KesKim commented Feb 4, 2020

I have a couple of ScriptableObjects where the [ReadOnly] attribute was handy for some ScriptableObjects, blocking user intereference with some fields I only wanted to view for debug in the Inspector when selecting these ScriptableObject Assets.

After upgrading to 2.0.1, the [ReadOnly] no longer does anything to disable the fields as it used to.

Both versions 1.0.3 and 2.0.1 of NaughtyAttributes tested in Unity 2019.3.0f5.

@dbrizov
Copy link
Owner

dbrizov commented Feb 4, 2020

Just tested it in Unity 2019.3.0f6 and 2019.2.17f2, and it's working. Check if you have other plugins overriding the inspector.

image

@KesKim
Copy link
Author

KesKim commented Feb 4, 2020

Must be my mistake - you are correct; I didn't account to the possibility of us changing the type of the field at some point in between the version changes and it does seems like it's a [System.Serializeable] type class with a CustomInspector of its own.

And I just found your main page documentation on this:

Most of the attributes are implemented using Unity's CustomPropertyDrawer, so they will work in your custom editors. If you want all of the attributes to work in your custom editors, however, you must inherit from NaughtyInspector and use the NaughtyEditorGUI.PropertyField_Layout function instead of EditorGUILayout.PropertyField.

I'll test this right away!

@KesKim
Copy link
Author

KesKim commented Feb 4, 2020

Wait, does that workflow even apply for [CustomPropertyDrawer]s in Editor/ folders? The CustomPropertyDrawer I have seems unable to reference NaughtyAttributes namespace, and it's inheriting from UnityEditor.PropertyDrawer not Editor so even if I could reference it, NaughtyInspector/UnityEditor.Editor would not be a suitable replacement.

Any suggestions?

At this moment this Issue is no longer named to describe the actual problem which would now be: "Need a [CustomPropertyDrawer] workaround similar to inheriting NaughtyInspector on custom Inspectors"

@dbrizov
Copy link
Owner

dbrizov commented Feb 4, 2020

You have an Editor or a CustomPropertyDrawer for your scriptable object?

@KesKim
Copy link
Author

KesKim commented Feb 4, 2020

You have an Editor or a CustomPropertyDrawer for your scriptable object?

CustomPropertyDrawer.

@dbrizov
Copy link
Owner

dbrizov commented Feb 4, 2020

In that case [ReadOnly] should work, because It's also implemented with a CustomPropertyDrawer which targets all fields with the [ReadOnly] attribute. I need to investigate this.

@dbrizov
Copy link
Owner

dbrizov commented Feb 4, 2020

Do you apply the [ReadOnly] attribute to the ScriptableObject property, or you are using the [ReadOnly] attribute for the properties inside the ScriptableObject?

@KesKim
Copy link
Author

KesKim commented Feb 4, 2020

Apologies, I seem to be changing the description constantly - I'm getting mixed up in changes in our codebase. I realise that must've wasted some of your time since I can't now find the CustomPropertyDrawer issue examples I was talking about... It seems to be a List and one List where X is a System.Serializable class, and that List is in a ScriptableObject.

I'm trying to double-check and clarify here now. [ReadOnly]+[CustomPropertyDrawer] DO seem to work. Again, my apologies for the hassle. Some examples that don't seem to work with [ReadOnly]:

Case, List on ScriptableObject

    public class BootConfigurationManager : ScriptableObject
    {
        [ReadOnly]
        // ReadOnly works correctly (BootConfiguration is another ScriptableObject)
        public BootConfiguration ActiveConfiguration;

        [ReadOnly]
        // ReadOnly does not seem to work
        [SerializeField] private List<string> EditModeScenePaths;

Another case, List<System.Serializable class> on ScriptableObject:

    public class SceneList : ScriptableObject
     {
          [ReadOnly]
          // ReadOnly doesn't work
          public List<RuntimeSceneInfo> ScenesInBuild;

So it seems to be List that is the issue, not what I panicked about initially.

@KesKim
Copy link
Author

KesKim commented Feb 4, 2020

Aaand further than that - seems the issue was only troubling where I was looking at EMPTY Lists!
The Size/Count Inspector field is editable on [ReadOnly] Lists, which caused me to think the Lists can be modified via Inspector (which they can, since the Size-field can delete or add entries which is undesired if the List is ReadOnly).

@dbrizov
Copy link
Owner

dbrizov commented Feb 4, 2020

Unity works a little strangely. In the case of a list, the CustomPropertyDrawer actually applies the attribute to each element of the list, not the list itself.

image

Anyway, I am glad we got to the bottom of it :)

@dbrizov dbrizov closed this as completed Feb 4, 2020
niggo1243 added a commit to niggo1243/NaughtyAttributes that referenced this issue Sep 6, 2021
niggo1243 added a commit to niggo1243/NaughtyAttributes that referenced this issue Sep 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants