Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question UI Toolkit Animation Curve

Discussion in 'UI Toolkit' started by Ruffian0305, Sep 26, 2023.

  1. Ruffian0305

    Ruffian0305

    Joined:
    Feb 23, 2015
    Posts:
    8
    Hello! I am simply puzzled over why the
    .ranges
    is not working properly on the
    CurveField
    for the UI Toolkit. The first issue that that it doesn’t adhere to ranges at all. Second issue is it doesn’t visually update, even with a
    MarkDirtyRepaint()
    (Unity 2022.3.7f1)

    I have a curve field, and I can change the range:

    Code (CSharp):
    1. float width = maxX.value -  minX.value;
    2. responseCurve.ranges = new Rect(minX.value, 0f, width, 1f);
    And I can trigger that code just fine. You can see in the output that the range is computed correctly as well.


    However, it doesn’t adhere to it at all.
    In the picture, you can see the curve that appears to be displaying correctly, however once you click into the range editor you can see that you can go out of the range:


    Compared to doing the same thing in an editor script, where it properly locks the range:

    Code (CSharp):
    1. float width = xMax - xMin;
    2. return EditorGUILayout.CurveField("Response Curve",value, Color.red, new Rect(xMin, 0f, width, 1f));


    For the second issue, I just don’t know!
    This is what it looks like after changing the range and saving (debug does say the range is correc)t:


    However, this is what it looks like after simply closing/reopening:


    As you can see, it does update it (still doesn’t adhere to it though) , but you have to do a hard refresh to get it to display properly even after calling
    responseCurve.MarkDirtyRepaint()


    Any tips/advice/help would be greatly appreciated! This is our last piece for this editor and it’s been killing us!

    Thank You for your time!
     
    oscarAbraham likes this.
  2. oscarAbraham

    oscarAbraham

    Joined:
    Jan 7, 2013
    Posts:
    431
    Hi, I can confirm that these are bugs. I've known about UITK's Animation Curve Field being buggy for a while, but I haven't had time to make reproduction cases to report its bugs, and then I forgot. Maybe you could report them? If you can't, I do plan to set a time next week to report a number of UITK/Editor bugs, and I'd include these.

    As a temporary workaround, you could use an IMGUIContainer to implement curve fields with IMGUI.
     
  3. Ruffian0305

    Ruffian0305

    Joined:
    Feb 23, 2015
    Posts:
    8
    At least I am not just losing my mind!! I have been squirreling through all the docs, etc. trying to figure out where I went wrong lol. I haven't reported a bug (ever) yet, as I always assume it is me misunderstanding something. If you can point me in the right direction, I might be able to figure it out :)

    Thank you for the pointer in the right direction as far as IMGUIContainer... I haven't worked with that yet, so will try and figure it out.
     
  4. oscarAbraham

    oscarAbraham

    Joined:
    Jan 7, 2013
    Posts:
    431
    :D I've felt like that sometimes too. In this case, I say these are bugs because the field doesn't use it's range property properly for some things, it doesn't behave like its IMGUI counterpart. Plus, I looked at the source code on GitHub and there are some clear mistakes there; for example, you can clearly see that they aren't passing the range in
    ShowCurveEditor
    .

    About reporting bugs. There's a special window for that in the menu:
    Help -> Report A Bug...
    . Unity has a help page about it here. Their site says that you may need to provide email address, but it's taken automatically from your Unity account.

    As an additional tip, I believe it's much more likely that the bug will be fixed if you provide a reproduction example. Even if the bug is really really simple to reproduce, your chances are much better with an example. If the bug it's so simple that there's no code or assets involved, describe the steps required to reproduce the bug as a numbered list. If you can, I recommend submitting a custom reproduction example folder that's a simple as possible, instead of a whole project.

    In general, the simpler you can make things for the QA person that processes your report first, the better, as Unity is big and they may not be an expert in this particular topic. So, adding some images for things that are hard to describe with words may help sometimes? To be honest, I've never done that, but it seems like a good idea for the second bug you described here. Or maybe you could just add a link to this forum thread.

    Finally, I recommend sharing the report ID here in the forums. A Unity developer that actually works on UI will probably see it, and it may help them to notice the bug report faster.

    No problem :). I think you already know how to use most of it. All those EditorGUI methods are IMGUI.

    EDIT
    Also, I'd recommend quoting or tagging people when responding in the forums. It helps them notice because they get a notification.
     
    Last edited: Sep 27, 2023