Code Monkey home page Code Monkey logo

unity-serializereferenceextensions's Introduction

Header_1

I am an indie game developer.

I love programming and often create complex game logic and useful libraries.

Twitter (X) / Zenn

Libraries for Unity

Libraries developed for game development can be found here.

These libraries were created with a smooth development workflow in mind.

Latest release (In active development)

This library is a scene management framework currently under active development. Your contributions are welcome !

ReadMe CardReadMe Card

Awesome libraries

ReadMe CardReadMe CardReadMe CardReadMe CardReadMe CardReadMe CardReadMe CardReadMe Card

Thank you for sponsor. Private sponsor and one-time donate are also welcome.

If you feel that my works are worthwhile, I would greatly appreciate it if you could sponsor me.

GitHub Sponsors: https://github.com/sponsors/mackysoft

unity-serializereferenceextensions's People

Contributors

chadefranklin avatar github-actions[bot] avatar johannesdeml avatar mackysoft avatar repiteo avatar shiena avatar theo-rapidfire avatar yellowisher avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

unity-serializereferenceextensions's Issues

[BUG] Duplicated element reference to the same object

What happened?

Bug Desc

When an element in a list is duplicated, it'll reference to the same object!

Expected Output

When duplicated, it should create a new reference, so that it's easier to handle repetitive list that has almost identical values.

Recording.2023-09-30.234354.mp4

Package Version

1.1.9

Unity Version

2022.2.17

[IMPROVE] Allow Script Location Move Without Losing Serialized Data

Improvement destription

So currently, it looks like if you Serialize a reference (say, to an object implementing an interface) through the SubclassSelector attribute, and then you move that script file, you lose all your serialized data for every reference that used that subclass/implementation.

Is there a way this could be worked around and improved? Or is this a limitation of SerializedReference on Unity's part?

I absolutely love these extensions, but it feels a bit too dangerous to use something that could wipe out tons of my serialized data if I ever refactor and forget I can't move certain scripts.

[BUG] Using it in List makes all of the same type be a single reference

What happened?

In most cases when you add an element with the same type on a list, they have the same reference, so when I edit one of the, the other also get editted.

On the following image, whenever I change "Burn" to anything, both changes. Look that 'Element 2' is of the same type but I can set another value for 'Status Effects', don't know why on this one worked ok.
image

Also, sometimes the layout of the inspector is not resized correctly when you change types.
(and I'd say its better empty than for the "missing type select")

Package Version

1.1.6

Unity Version

2020.3.3f1

[IMPROVE] use JsonUtility to serialise and then deserialise into the new type

Improvement destription

When changing a type, it would be good to serialise the current value, and then deserialise into the new object instead of using the activator. That way, any properties they share will be retained.

I would also add a “make unique” button that just clones the object (also using jsonutility), useful after a “duplicate array” operation. This could be a little button next to the selector (or a … button that opens a menu).

[BUG]

What happened?

A bug happened!

Selector doesn't draw anything and gives this error

NullReferenceException: Object reference not set to an instance of an object UnityEngine.GUILayoutEntry.ApplyStyleSettings (UnityEngine.GUIStyle style) (at /Users/bokken/build/output/unity/unity/Modules/IMGUI/LayoutEntry.cs:72) UnityEngine.GUILayoutEntry.set_style (UnityEngine.GUIStyle value) (at /Users/bokken/build/output/unity/unity/Modules/IMGUI/LayoutEntry.cs:31) UnityEngine.GUILayoutEntry..ctor (System.Single _minWidth, System.Single _maxWidth, System.Single _minHeight, System.Single _maxHeight, UnityEngine.GUIStyle _style, UnityEngine.GUILayoutOption[] options) (at /Users/bokken/build/output/unity/unity/Modules/IMGUI/LayoutEntry.cs:61) UnityEngine.GUILayoutUtility.DoGetRect (System.Single minWidth, System.Single maxWidth, System.Single minHeight, System.Single maxHeight, UnityEngine.GUIStyle style, UnityEngine.GUILayoutOption[] options) (at /Users/bokken/build/output/unity/unity/Modules/IMGUI/GUILayoutUtility.cs:482) UnityEngine.GUILayoutUtility.GetRect (System.Single minWidth, System.Single maxWidth, System.Single minHeight, System.Single maxHeight, UnityEngine.GUIStyle style, UnityEngine.GUILayoutOption[] options) (at /Users/bokken/build/output/unity/unity/Modules/IMGUI/GUILayoutUtility.cs:476) UnityEditor.EditorGUILayout.GetControlRect (System.Boolean hasLabel, System.Single height, UnityEngine.GUIStyle style, UnityEngine.GUILayoutOption[] options) (at /Users/bokken/build/output/unity/unity/Editor/Mono/EditorGUILayout.cs:2104) Sirenix.Utilities.Editor.SirenixEditorGUI.ToolbarSearchField (System.String searchText, System.Boolean forceFocus, System.Single marginLeftRight) (at <d5a36a96b2ad42b898b2ec8b30fb6453>:0) Sirenix.Utilities.Editor.InstanceCreatorWindow.OnGUI () (at <d5a36a96b2ad42b898b2ec8b30fb6453>:0) UnityEditor.HostView.OldOnGUI () (at /Users/bokken/build/output/unity/unity/Editor/Mono/HostView.cs:268) UnityEngine.UIElements.IMGUIContainer.DoOnGUI (UnityEngine.Event evt, UnityEngine.Matrix4x4 parentTransform, UnityEngine.Rect clippingRect, System.Boolean isComputingLayout, UnityEngine.Rect layoutSize, System.Action onGUIHandler, System.Boolean canAffectFocus) (at /Users/bokken/build/output/unity/unity/ModuleOverrides/com.unity.ui/Core/IMGUIContainer.cs:351) UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&) (at /Users/bokken/build/output/unity/unity/Modules/IMGUI/GUIUtility.cs:189)

Package Version

1.1.9

Unity Version

2021.3.33f

[FEATURE] Ability to select the default concrete type of an abstract class

Feature destription

Description

Hi, thank you for this very useful package!

I have a suggestion to make the package more convenient to use, by being able to select the default concrete type of an abstract class rather than <null> like the image below (ex: default to DebugCommand). Is that possible? Or is it too complicated and not worth the time.
image

Thanks for your attention

Slow if work with custom inspector

There is a performance issue if that type has a custom inspector and a field opened.

[CustomEditor(typeof(Example))]
public class ExampleEditor : UnityEditor.Editor {
    //issue happen even no extra content
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();
    }
}

Untitled-1

Tested by Unity 2020.3.30

[BUG] 在Unity点击运行时会报错"Objects are trying to be loaded during a domain backup. This is not allowed as it will lead to undefined behaviour!"

What happened?

[BUG] 在Unity点击运行时会报错"Objects are trying to be loaded during a domain backup. This is not allowed as it will lead to undefined behaviour!",并且随着使用[SerializeReference, SubclassSelector]的频率而增加,是否时我使用不当还是本身的BUG,需要您的帮助

Package Version

1.1.7和1.1.9都有此问题

Unity Version

2021.3.9f1c1

Adding New Array Element Creates Duplicate References [BUG]

What happened?

When drawing an array of serializable classes (as SerializeField) that contains a SubclassSelector, adding a new instance to the array creates duplicate references to the subclass which is only fixed once manually choosing an implementation from the dropdown. I have attached a video of the issue.

bandicam.2022-03-28.09-52-54-708.mp4

Package Version

1.1.2

Unity Version

2020.3.30f1

[BUG] Error "Value cannot be null." when element of list is set to null.

What happened?

Hello, I have an array of serializable objects like this:
[SerializeReference, SubclassSelector] public ComposerConfiguration[] configurations;
The ComposerConfiguration is abstract class and base for other classes. When I try to add new element in the inspector I can correctly change to selected subclass from dropdown, however when the class is selected and I want to assign null again I get this error:

ArgumentNullException: Value cannot be null.
Parameter name: type
UnityEngine.JsonUtility.FromJson (System.String json, System.Type type) (at <e0dfe14b531f4aef959546c48a6f003b>:0)
MackySoft.SerializeReferenceExtensions.Editor.ManagedReferenceUtility.SetManagedReference (UnityEditor.SerializedProperty property, System.Type type) (at ./Library/PackageCache/com.mackysoft.serializereference-extensions@93d7e13f62/Editor/ManagedReferenceUtility.cs:19)
MackySoft.SerializeReferenceExtensions.Editor.SubclassSelectorDrawer.<GetTypePopup>b__10_1 (MackySoft.SerializeReferenceExtensions.Editor.AdvancedTypePopupItem item) (at ./Library/PackageCache/com.mackysoft.serializereference-extensions@93d7e13f62/Editor/SubclassSelectorDrawer.cs:119)
MackySoft.SerializeReferenceExtensions.Editor.AdvancedTypePopup.ItemSelected (UnityEditor.IMGUI.Controls.AdvancedDropdownItem item) (at ./Library/PackageCache/com.mackysoft.serializereference-extensions@93d7e13f62/Editor/AdvancedTypePopup.cs:135)

Am I possibly doing something wrong or it's just a bug? How to fix this?

One note that might possibly help, there is another abstract class between the used one and base one like this:

AbstractClassA : ComposerConfiguration
ActualClassB : AbstractClassA 

Package Version

1.2.1

Unity Version

2022.3.6

[IMPROVE] CustomPropertyDrawers not working

Improvement destription

Here there,

amazing work!
Unfortunately 'CustomPropertyDrawers' aren't working if I use the 'SubclassSelectorAttribute'. I tried to solve it but failed horribly.
Do you have any idea how one might get them to work?

Greetings,
Ben

New JSON and Copy/Paste features break plugin for Unity 2020

What happened?

Hi,
This is not really a bug but the README says backwards compatibility to Unity 2019 which does not seem correct anymore.

The issue is both features attempt to get the value of SerializedProperty.managedReferenceValue which is write only for Unity 2020 (any maybe prior did not look into when they changed this).
https://docs.unity3d.com/2020.3/Documentation/ScriptReference/SerializedProperty-managedReferenceValue.html

Considering this is a 3 year old version of unity it is understandable if you do not plan to fix this but if that is the case please update the README with which version of the plugin are supported on each Unity major version.

Thanks (love the plugin btw :))

Package Version

1.2.0

Unity Version

2020.3.48f1

Why no struct support?

I haven't found any Contributing or Questions guidelines, so sorry for the unformatted Issue 😢

There's any particular reason for support for Classes but not structs?
It's a very common use case (for me at least) use structs and implement interfaces.

[BUG] Nested addressable refs go missing with remote bundles

What happened?

Hey so basically I have a dialogue system with various options. One of the options opens a shop and has an asset reference to it.

    [System.Serializable]
    public class OpenShopOption : DialogueOptionBase
    {
        [Tooltip("The shop to open.")]
        [SerializeField] private AssetReferenceT<Shop> _shop;

and upon uploading the content and loading into the game, it is just empty. Not even "missing" as you might see sometimes. Im not sure if its an issue with Unity regressionables or the Addressable system simply doesnt recognize the ref IDs as something they should include as a dependency for this object. I dont really know how to get more info on this issue, but I will try to look into it more as well.

Package Version

1.1.9

Unity Version

2022.3.12f1

[IMPROVE] Consistence with Unity indentation

Improvement destription

The indentation of the field does not correspond to Unity expected indentation for nested SerializeReference.

Indentation between the foldout and the label:
image
image

The position of the foldout element does not correspond to what is expected either. Note: unity use 15 indent pixel.
image

image

The dropdown is more indented then what we expect.
image
image

Schema:
(AbilityDefinition - ScriptableObject)
-- [SerializeReference] (Ability - Plain Old C# Object)
---- [SerializeReference] (Statistic - IStatisticFloat)

Version: 2022.1.8f1, Library Version: 1.3.1

[BUG] References lost after changing asmdefs

What happened?

I decided to move some scripts into asmdefs today and all my interface list items lost their references. This is due to the asm not being automatically updated after recompile.

Before it was referencing the default C# asm:
type: {class: SetPlayFabDataOption, ns: Entities.Npcs.Dialogues, asm: Assembly-CSharp}

When it should be referencing the new one:
type: {class: PlayFabDataConditionalDialogue, ns: Entities.Npcs.Dialogues, asm: Tombstone}

Simply changing it in a text editor to the correct asm fixes it, but Im sure this can and should be automated :)

Package Version

1.1.7

Unity Version

2021.3.24f1

[BUG] [SubclassSelector] Does Not Support Concrete Base Class

What happened?

Desired Behavior

It is possible to create an instance of a field in the Unity inspector, on a field marked [SerializeReference, SubclassSelector], whose data type is a concrete, pure C# data.

Actual Behavior

Only <null> shows in the Unity inspector on a field marked [SerializeReference, SubclassSelector], whose data type is a concrete, pure C# data.

Code example:

using System;
using UnityEngine;

public class ReferenceTester : MonoBehaviour {
    [Serializable]
    public class Data {
        public int intValue;
    }

    [SerializeReference, SubclassSelector] private Data example;
}

image
image

Package Version

1.1.4

Unity Version

2021.2.15f1

[BUG] Multi-editing throws error

What happened?

I tried to multi-edit a property and when I tried to select a subclass from the picker, I got the following error:

Invalid reference data for SerializedProperty at path '<path-to-my-property-that-has-subclass-drawer>' and offset '160'
UnityEngine.StackTraceUtility:ExtractStackTrace ()
MackySoft.SerializeReferenceExtensions.Editor.SubclassSelectorDrawer:<GetTypePopup>b__9_1 (MackySoft.SerializeReferenceExtensions.Editor.AdvancedTypePopupItem) (at Library/PackageCache/[email protected]/Editor/SubclassSelectorDrawer.cs:81)
MackySoft.SerializeReferenceExtensions.Editor.AdvancedTypePopup:ItemSelected (UnityEditor.IMGUI.Controls.AdvancedDropdownItem) (at Library/PackageCache/[email protected]/Editor/AdvancedTypePopup.cs:135)
UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)

Only one of the selected objects updated properly.

I think this has something to do with the fact that the pop up is caching the property and modifying it afterwards, which loses the multi-edit information.

Perhaps caching the entire object (property.serializedObject) then modifying the property path would get around this?

Package Version

1.1.7

Unity Version

2022.1.23f

[IMPROVE] UI Toolkit Support

Improvement: UI Toolkit Support

Hello! This is a great little extension--makes SerializeReference much more useful out of the box.

Due to Unity's restrictions/issues with UI tooolkit and IMGUI inspectors clashing, it would be nice to have UI Toolkit version of the subclass selector implemented.

I did this locally just to quickly unblock something. Simply added this method to SubclassSelectorDrawer. I'd make a PR but I'm not sure this is how you'd want to do it with your package anyway. It doesn't totally match the styling of your IMGUI implementation.

        public override VisualElement CreatePropertyGUI(SerializedProperty property)
        {
            VisualElement root = new();

            if (property.propertyType == SerializedPropertyType.ManagedReference)
            {
                Button dropdownButton = null;
                dropdownButton = new Button(() =>
                {
                    TypePopupCache popup = this.GetTypePopup(property);
                    this.m_TargetProperty = property;
                    popup.TypePopup.Show(dropdownButton.contentRect);
                });

                dropdownButton.text = this.GetTypeName(property).text;
                root.Add(dropdownButton);

                PropertyField propertyField = new(property);
                root.Add(propertyField);
            }
            else
            {
                TextField text = new(SubclassSelectorDrawer.k_IsNotManagedReferenceLabel.text);
                root.Add(text);
            }

            return root;
        }

[BUG] SubclassSelector attribute works in Unity, but VSCode doesn't recognize it

What happened?

Expectation:
VSCode would recognize the attribute

Reality:
VSCode spits out the following two errors when the attribute is used:
"The type or namespace name 'SubclassSelectorAttribute' could not be found (are you missing a using directive or an assembly reference?) [Assembly-CSharp]"
"The type or namespace name 'SubclassSelector' could not be found (are you missing a using directive or an assembly reference?) [Assembly-CSharp]"

As stated, the attribute works in Unity. I can select a subclass and set its fields without any issues. There's probably just some configuration that I need to adjust in VSCode, but I'm not sure how that would be done.

Package Version

1.1.7

Unity Version

2021.3.14f1

[IMPROVE] Subclass Selector Dropdown Menu

Improvement description

I would love it if when using AddTypeMenu attribute to show a custom display name in the SubclassSelector dropdown menu, it would support using paths in order to separate the dropdown contents into categories & submenus. Similar to the AddComponent menu and other Unity menu attributes like ContextMenu, AddMenu, CreateAssetMenu etc.

This would allow for a more scalable interface and organization in the editor when working with larger projects.

Thanks

Property Height Not Updating Immediately [BUG]

What happened?

When drawing an array of serializable classes (as SerializeField) that contains a SubclassSelector, the property height does not update immediately when changing the type. The weird part is that logging "Debug.Log(EditorGUI.GetPropertyHeight(property,true));" did show it updating immediately. I also wrote my own Custom Property Drawer which does not have this issue, though I cannot figure out why. I have attached a video of the issue.

bandicam.2022-03-28.09-34-47-997.mp4

Here is a video of my version without the issue:

bandicam.2022-03-28.10-03-44-584.mp4

and the code:

https://gist.github.com/chadefranklin/cd2e6c4d89928ce25274395ff8690f9a

Package Version

1.1.2

Unity Version

2020.3.30f1

[BUG] Cant copy/paste in the inspector

What happened?

Copying a single interface reference wont let you paste it at all.

If you have an array of interfaces, you can copy the array and paste it, but the pasted array is just full of null values.

Package Version

1.1.7

Unity Version

2021.3.27f1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.