question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Bug][Expandable] Will make other expandable element which in front of this Attirbute not update

See original GitHub issue

Here’s the code that reproduce the bug:

    public class ExpandableTest : MonoBehaviour
    {
        public UnityEvent onClick;//Bug: the List can't be modify
        [ResizableTextArea]
        public string multiLine;//Bug: the content can't be save after hit 'Enter'
        [Expandable]
        public ScriptableObject obj0;
    }

When you edit the onClick/multiLine field in Inspector, you will find that their value will not get save: image

But if you move the obj0 on top of the onClick/multiLine field, they will work again.

Unity Version: 2021.2.7f1c1

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
rhys-vdwcommented, Jan 4, 2022

I have discovered that if you remove this line the issue goes away.

https://github.com/dbrizov/NaughtyAttributes/blob/178959b4f9ded9aead6cd1f9a80decf41b9b6812/Assets/NaughtyAttributes/Scripts/Editor/PropertyDrawers/ExpandablePropertyDrawer.cs#L74

My guess is that when the drawer is called on the blur event this code will somehow reset the value on the main inspector object before it has a chance to commit the changes via the final call to ApplyModifiedProperties here:

https://github.com/dbrizov/NaughtyAttributes/blob/178959b4f9ded9aead6cd1f9a80decf41b9b6812/Assets/NaughtyAttributes/Scripts/Editor/NaughtyInspector.cs#L133

Why this is affecting the main object is not clear to me though, presumably some subtlety of other changes in the problematic commit.

Actually I see no issue with line removed. I assume the purpose of this line is to ensure that the nested editor is in sync with the asset. I tested this by opening a second inspector and modifying the nested asset there. Regardless of the presence of this line the asset will update correctly as soon as the mouse enters the inspector of the object with the Expandable attribute.

Looking at the docs we see:

If you keep a reference to a SerializedObject instance for more than one frame, you must make sure to manually call its SerializedObject.Update method before you read any data from it, as one or more target objects may have been modified elsewhere, such as from a separate SerializedObject stream.

source: https://docs.unity3d.com/ScriptReference/SerializedObject.html

This suggests to me that this line is not required as the SerializedProperty reference appears to be recreated on every invocation of OnInspectorGUI.

I will open a PR with this simple change.

0reactions
dbrizovcommented, Feb 6, 2022

#295 PR merged into the v2 branch 7cddf69bca9d09eb8205498ebaf6bdc50f7641fd

Read more comments on GitHub >

github_iconTop Results From Across the Web

Make absolute positioned div expand parent div height
You answered the question yourself: I know that absolute positioned elements are removed from the flow, thus ignored by other elements.
Read more >
Expandable Sections Within a CSS Grid
I'm quite comfortable wrangling CSS Grid to produce interesting layouts, while keeping the HTML markup clean and simple. But recently, I was ...
Read more >
Creating a Textarea with dynamic height using React and ...
Introduction. In this article, I'll show you how to create a <textarea> that automatically grows and shrinks depending on the content within.
Read more >
Sheets: bottom
Expanding bottom sheets provide a small, collapsed surface that can be expanded by the user to access a key feature or task. They...
Read more >
Advanced layouts with absolute and fixed positioning
Absolutely positioned elements are removed entirely from the document flow. That means they have no effect at all on their parent element or...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found