Events Closest Snap Position and Snapped to Item return incorrect index when set to looping

Issue #13 wontfix
Former user created an issue

Events Closest Snap Position and Snapped to Item do not return correct index when Loop is enabled.

With 3 items, both functions return index 1 for all three items. When disabling Loop the functions correctly return index 0, 1 and 2.

Expected behavior Return 0, 1 and 2 for the three items with looping enabled. When looping back from item 3 to item 1, the functions should return index 0 again. And when looping forward from item 1 to item 3, the functions should return index 2.

Comments (2)

  1. Beka Westberg repo owner

    Thanks for sending in this bug report!

    So the behavior you have described is obviously bad, but sadly it’s not trivial to fix :/

    What I would recommend doing is:

    1. Grab the child at the passed index.
    2. Do logic based on that child (RectTransform), rather than the index.

    public void SnappedToItem(int index)
        {
            RectTransform child = null;
            m_ScrollSnap.GetChildAtSnapIndex(index, out child);
            Debug.Log(child);
    
            // Do other logic based on child.
        }
    

    I tested and GetChildAtSnapIndex returns the correct child.

    Sorry I can’t be more help to you :/ And thanks again for sending in this bug report! It was very helpful and descriptive :D

    --Beka

  2. Log in to comment