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

No Atributes seem to be working after upgrading to Unity 6 LTS #392

Open
PalaNolho opened this issue Nov 4, 2024 · 3 comments
Open

No Atributes seem to be working after upgrading to Unity 6 LTS #392

PalaNolho opened this issue Nov 4, 2024 · 3 comments

Comments

@PalaNolho
Copy link

PalaNolho commented Nov 4, 2024

Hi, I have this very simple ShowIf where I have a bool and I want to show/hide a vector and a float based on that bool.
I have tried in a ScriptableOject and in a normal Script but in either case, nothing happened. The properties are always visible regardless if the bool is true or false.

I noticed that the [ReadOnly] and [ShowAssetPreview] were not doing anything either so it seems to be a general problem after Unity 6 Upgrade (or a me general problem)

Can you help?
Thanks.

image

@PalaNolho PalaNolho changed the title ShowIf is not doing anything No Atributes seem to be working after upgrading to Unity 6 LTS Nov 4, 2024
@TylerTemp
Copy link

TylerTemp commented Nov 5, 2024

About the question itself:

This is possibly related to: #369

I have become aware of this checkbox in the project settings. Not a fan of it, but I guess it could be a workaround. Screenshot_2023-08-22-10-45-23_Unity

After this, if things still not work, check this to debug: SaintsField/issues/51

If it works now, that means there are scripts that override CustomEditor which is way too high priority. If it does not work, then sorry buddy there is indeed some problem with your project that I can not think of.

If this script works, there is a (very annoying) way to find out which hijake it:

foreach (Assembly asb in AppDomain.CurrentDomain.GetAssemblies())
{
    Type[] allTypes = asb.GetTypes();
    List<Type> allEditors = allTypes
        .Where(type => type.IsSubclassOf(typeof(UnityEditor.Editor)))
        .ToList();

    foreach (Type eachEditorType in allEditors)
    {
        foreach (CustomEditor customEditor in eachEditorType.GetCustomAttributes<CustomEditor>(true))
        {
            var v = typeof(CustomEditor)
                .GetField("m_InspectedType",
                    BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic |
                    BindingFlags.Public | BindingFlags.DeclaredOnly | BindingFlags.FlattenHierarchy)
                ?.GetValue(customEditor);
            Debug.Log($"Found editor: {eachEditorType} -> {customEditor}: {v}");
        }
    }
}

It'll print all the editor for it's corresponding types. Carefully check overrides like UnityEngine.Object, MonoBehavior, Component, which should be the one that blocked other inspectors.


Off the question: NaughtyAttributes hasn't been updated for years with many pending PR not merged. Since Unity 2022, Unity recommended to use UI Toolkit for editor, and NaughtyAttributes still only support IMGUI.

I'd suggest some project as a replacement:

  1. SaintsField, inspired by NaughtyAttributes. Already have all functions of NA, with many more new decorators.
  2. Tri-Inspector. If you use Odin you'll love this. 900+ stars already

Example in Unity 6000.0.24f1:

using SaintsField;
using SaintsField.Playa;

public bool animateCursor;
// this one can co-exist with NaughtyAttributes, but won't work with array/list
[ShowIf(nameof(animateCursor))] public float animationSpeed;
// this one requires you to enable SaintsEditor first, does not compatible with NaughtyAttributes
[PlayaShowIf(nameof(animateCursor))] public Texture2D[] cursorAnimation;
Unity_63tu2oPw0K.mp4

@PalaNolho
Copy link
Author

@TylerTemp the SaintsField seems to be a more direct replacement.
As for the Tri-Inspector, I was thinking of getting Odin at some point to be fair. would this one be a replacement for Odin or something to use together?

@TylerTemp
Copy link

@TylerTemp the SaintsField seems to be a more direct replacement. As for the Tri-Inspector, I was thinking of getting Odin at some point to be fair. would this one be a replacement for Odin or something to use together?

  1. Using SaintsField with Odin is fine for most of the time, but note: 1, Odin does not respect Unity UI Toolkit length class, which Odin never solve this issue. Under Odin, SaintsField's field length will not properly aligned with other fields. (I asked Odin if there is a way to solve this on my side, they never response me...) 2, any Editor level attributes will not work (this is fine because Odin already has alternatives of these attributes, and even more powerful)
  2. Tri-Inspector, I'm not sure. but from there description:

    Tri Inspector is able to work in compatibility mode with Odin Inspector. In this mode, the primary interface will be drawn by the Odin Inspector. However, parts of the interface can be rendered by the Tri Inspector.

The general idea is, all pure PropertyDrawer will just work fine under Odin. For example, NA's all Drawer Attributes (anything not under meta attributes) will also work under Odin.

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