microsoft / MixedRealityToolkit-Unity

This repository is for the legacy Mixed Reality Toolkit (MRTK) v2. For the latest version of the MRTK please visit https://github.com/MixedRealityToolkit/MixedRealityToolkit-Unity
https://aka.ms/mrtkdocs
MIT License
6k stars 2.12k forks source link

MRTK ScrollingObjectCollection doesn't work correctly #10350

Closed xandrew94x closed 9 months ago

xandrew94x commented 2 years ago

Hi, I'm building a ScrollingObjectCollection, but the objects inserted in the list do not scroll correctly.

I noticed that when I put the objects in the container before playing scene the scroll object works well.

If instead I insert the objects in runtime, the container shows only the first objects and by activating the scroll they are not scrolled even though the objects are present. I mean, the scroll is activated, but trying to scroll, the animation always returns me to the first objects. Also, after added the objects into grid i applied the UpdateCollection() method.

5vh90h

Setup:

Target Platform:

The object setups are:

scrollobject

gridobjectcollection

gerarchia

Originally posted by @xandrew94x in https://github.com/microsoft/MixedRealityToolkit-Unity/issues/10333#issuecomment-979039880

polar-kev commented 2 years ago

Hi @xandrew94x, are you running this in the Unity editor or on device?

xandrew94x commented 2 years ago

Hi @polar-kev , I noticed that the problem is both on device and in the editor.

polar-kev commented 2 years ago

Components should be configurable from code at runtime so this is definitely a bug @xandrew94x. Thanks for filing.

MaxWang-MS commented 2 years ago

Hi @xandrew94x, could you try calling ScrollingObjectCollection.UpdateContent() after modifying the collection? That should solve the problem you are facing.

xandrew94x commented 2 years ago

Thanks for the reply @polar-kev and @MaxWang-MS.

Components should be configurable from code at runtime so this is definitely a bug @xandrew94x. Thanks for filing.

Maybe it is. it's like if methods don't interact with the object.

Hi @xandrew94x, could you try calling ScrollingObjectCollection.UpdateContent() after modifying the collection? That should solve the problem you are facing.

I made several tests. I tried calling ScrollingObjectCollection.UpdateContent() and GridObjectCollection.UpdateCollection() after inserting the elements. Alternating methods or entering both. I also tried calling these methods before and after inserting new objects. (Objects within the grid, if any, are deleted and re-added)

Schroedingers-Cat commented 2 years ago

If instead I insert the objects in runtime, the container shows only the first objects

I'm seeing the same issue with the GridObjectCollection's UpdateCollection() call via script. To work around this, I'm using a coroutine to delay the call by an additional frame when updating the collection during Awake/Start.

MaxWang-MS commented 2 years ago

Hi @xandrew94x and @Schroedingers-Cat, I have tried but failed to reproduce the issue you mentioned. In my testing both SOC and GOC are correctly updated after calling UpdateContent() and UpdateCollection() respectively. If you are still encountering this issue, please provide us with more information (a min repro will work the best). Thanks.

xandrew94x commented 2 years ago

Hi @xandrew94x and @Schroedingers-Cat, I have tried but failed to reproduce the issue you mentioned. In my testing both SOC and GOC are correctly updated after calling UpdateContent() and UpdateCollection() respectively. If you are still encountering this issue, please provide us with more information (a min repro will work the best). Thanks.

Hi @MaxWang-MS, here you can find a sample repo where the issue happen.

The code simply clears and fills the list every n seconds. You can set the waitingTime from the editor. Also I inserted a flag to change from method UpdateContent() to method UpdateCollection().

If instead I insert the objects in runtime, the container shows only the first objects

I'm seeing the same issue with the GridObjectCollection's UpdateCollection() call via script. To work around this, I'm using a coroutine to delay the call by an additional frame when updating the collection during Awake/Start.

@Schroedingers-Cat Thanks for the answer. I tried also with a Coroutine method, but the problem persists. Furthermore, my task does not include updating only during Awake/Start.

argenestel commented 1 year ago

I am looking solution for this. I instantiated buttons and called updatecontent and updatecollection through script. I can scroll when i change mask mode auto while it's running in unity editor but can't really scroll any other way.

AdCCooN commented 1 year ago

is there any fix for this issue at this point?

tkapu commented 1 year ago

Wasn't able to find a workaround. Still not usable.

IssueSyncBot commented 9 months ago

We appreciate your feedback and thank you for reporting this issue.

Microsoft Mixed Reality Toolkit version 2 (MRTK2) is currently in limited support. This means that Microsoft is only fixing high priority security issues. Unfortunately, this issue does not meet the necessary priority and will be closed. If you strongly feel that this issue deserves more attention, please open a new issue and explain why it is important.

Microsoft recommends that all new HoloLens 2 Unity applications use MRTK3 instead of MRTK2.

Please note that MRTK3 was released in August 2023. It features an all new architecture for developing rich mixed reality experiences and has a minimum requirement of Unity 2021.3 LTS. For more information about MRTK3, please visithttps://www.mixedrealitytoolkit.org.

Thank you for your continued support of the Mixed Reality Toolkit!

Jukka-L commented 6 months ago

I had this problem as well. As a kind of workaround it works somewhat well if you keep the object collection game object deactivated by default, instantiate the prefabs first and then activate the game object after everything is instantiated.

ullriche commented 3 months ago

I found a workaround that works for my problem. It's a combination of the before-mentioned fixes but I still wanted to mention it.

Original problem: The elements in the GridObjectCollection would not update correctly and were displaced, although I called GridObjectCollection.UpdateCollection(). The fix for that was to call GridObjectCollection.UpdateCollection() in a Coroutine, effectively waiting a frame to call it after having updated the children of the GridObjectCollection.

That fixed the issue of displaying, but now I couldn't scroll properly. My fix for that was to call ScrollObjectCollection.UpdateContent() also from the Coroutine and after GridObjectCollection.UpdateCollection(). This works for me, hopefully for you as well.


void someFunc()
{
    .....
    // Remove Children from GridObjectCollection
    // Add new Children to GridObjectCollection
    m_ScrollCollection.MoveToIndex(0); // Scrolls to the top [optional]
    StartCoroutine("InvokeUpdateCollection");
}

private IEnumerator InvokeUpdateCollection()
{
    yield return null;
    m_GridCollection.UpdateCollection();
    m_ScrollCollection.UpdateContent();
}