Giter VIP home page Giter VIP logo

Comments (4)

RoryDungan avatar RoryDungan commented on September 26, 2024

I had a go of modifying the slider example from our example project to use min values other than 0.

What I observed was that moving the sliders worked as expected, and I could move one slider beyond the minimum value of the other one fine.
scrollbar

I noticed that when I changed the value the slider was bound to externally to a value outside the range of the slider, the property would be set once with that value, then immediately again with the min value of the slider. Is this the issue you're talking about?
scrollbar-2

from unity-weld.

marijneken avatar marijneken commented on September 26, 2024

Thanks for the in depth tests. No, that's not the issue I'm having. I just did some more tests and I'm having a hard time debugging it.
The problem is, that this problem doesn't show up in the UI. Like your example, my slider is working fine and if I connect a Text object to it, it shows the correct value all the time.

The thing is though, in my "set" method for this property I'm also calling PlayerPrefs.SetInt("DayOfYear", value). When my application is restarted, I'm reading that value back from the PlayerPrefs. And THAT'S how I discovered the problem. Somehow, my property's "set" method is called with an incorrect value, and somehow at the same time the UI doesn't reflect that wrong value. I want the range to be [1, 365], but that results in PlayerPrefs always storing the value 1 (well, it's the last value that's written). If I set the range of the slider to [0, 365], everything works as expected.

Since this incorrect value seems to come from Unity's side, I'm not sure there's anything you could do really. These are the two consecutive calls I get:
image

image

That last zero gets changed into a 1 later, because it's outside the range. As you might notice, the localCursor value for the second call is a lot more to the left, compared to the first call. I noticed that this is something that happens during debugging, because I moved my mouse pointer to my screen on the left after the first breakpoint was hit. So at one point I thought that this whole problem might only occur during debugging, but that's not the case as I can see by the value that is stored by the PlayerPrefs call.

So, right now I've just decided to set the range to [0, 365] and live with it. It's pretty confusing to me why the call with this wrong value happens and how it could be that the UI is NOT showing this wrong value. Maybe I'm doing something wrong, but my code is pretty simple so I don't think it's me:

[Binding]
public int DayOfYear
{
    get
    {
        return dayOfYear;
    }
    set
    {
        if (dayOfYear == value)
        {
            return; // No change.
        }

        dayOfYear = value;
        PlayerPrefs.SetInt("DayOfYear", value);
        OnPropertyChanged("DayOfYear");
    }
}

from unity-weld.

RoryDungan avatar RoryDungan commented on September 26, 2024

Hmm looks like this is the just way Unity UI works. I'll close this for now because it looks like you have a workaround and I'm not sure what we could do from our side to fix it, but let us know if you have an idea how we could better handle it.

from unity-weld.

marijneken avatar marijneken commented on September 26, 2024

Fair enough. I also noticed that when I place an OnPropertyChanged call somewhere in my code to trigger a UI update, besides the "get" method, the "set" method is also called by Unity. Pretty strange and wrong behavior in my opinion.

from unity-weld.

Related Issues (20)

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.