Author Topic: Wrapcontent doesn't apply to children added at runtime to Prefabs  (Read 1620 times)

Shifty Geezer

  • Full Member
  • ***
  • Thank You
  • -Given: 7
  • -Receive: 9
  • Posts: 226
    • View Profile
I had an interface with two selectors (scrollviews in a frame with a few labels, etc) using Wraparound Content. I add items to these scrollviews at runtime (using NGUITools.AddChild), adding +100 to x pos for each item, and when they are drawn at start the contents are wrapped correctly so the starting selected item is in the centre of the list of items.

I've made some changes to the layout and decided to create a prefab to keep the interfaces consistent without having to manually edit. I just copied the first selector as a prefab and pasted it into the scene as the second. The wraparound content script didn't wrap the content on creation of the duplication, only when scrolled, leaving a lot of space to the left of centre in the scrollview. More significant, reloading the scene caused wraparound to break on the original selector so now neither scrollview experiences wraparound of content at start.

I can work around this by disabling the Wraparound script in the prefab and then enabling after adding the children.
« Last Edit: January 10, 2016, 11:17:12 AM by Shifty Geezer »


  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Wrapcontent doesn't apply to children added at runtime to Prefabs
« Reply #1 on: January 11, 2016, 05:22:20 PM »
Wraparound script? You mean UIWrapContent? It runs its logic in UIWrapContent.Start(). Depending what you duplicated, it may or may not execute. I'm pretty sure if you duplicate existing scene objects, it won't for example. If you instantiate prefabs it should, however. I can only suggest adding Debug.Logs in there to see if it's being called correctly.