Content Scroll Snap raises exception when content is null

Issue #354 resolved
Simon Jackson created an issue

Reported by Jamjardavies on Gitter.

Detail from Gitter
”Okay in my tests on a new project, I've added a "Content Scroll Snap Horizontal" from the create menu, and then removed the 5 children it comes with. I get no errors until I play and stop, to which I notice the ContentScrollSnapHorizontal has set it's enable to false. Upon enabling this component in the editor (in edit mode, not play mode), I start getting error spam in the console. Also, when adding children to the content using Awake, it works, but if I delay it (in Start for instance), it then doesn't work or snap. What I seem to need to do is enable the snap, and update the layout, but this still causes an exception, since there's no children at the start.”

Comments (2)

  1. Simon Jackson reporter

    Well, that was an interesting and fun ride, but you have a solution now.

    I’ve refactored the control and also put some protection in against having no child content.

    I have also added a new SetNewItems function which takes a list of transforms as a parameter, it’s also designed to work with Prefabs.

    The only thing to be aware of it either:

    • Your prefab have their anchors and positions set correctly
    • You have some sort of layout control in the content to ensure items that are added are laid out correctly.

    Shall have this pushed into dev today.

  2. Log in to comment