Author Topic: Dynamically adding a UILabel creates UI Root camera  (Read 16489 times)

mukulabdagiri

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 11
    • View Profile
Dynamically adding a UILabel creates UI Root camera
« on: July 18, 2016, 09:46:38 AM »
I have a main camera in my scene. My static UI elements such as score, lives, level, etc (which are UILabel) show up properly. I have placed them inside a HUD UIPanel. But in my game if i try to instantiate a gameobject which has a UILabel component attached to it, then a UI Root object gets created with a camera in it and that camera takes control and i lose my original game view.
How can i dynamically instantiate a gameobject with UILabel without having an extra camera getting created?

Thanks,
Mukul

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Dynamically adding a UILabel creates UI Root camera
« Reply #1 on: July 20, 2016, 03:16:40 AM »
You need to use gameObject.AddChild instead of Object.Instantiate to create your UI elements. All UI elements must be added as children of an existing UI, not created in the middle of nowhere.

mukulabdagiri

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 11
    • View Profile
Re: Dynamically adding a UILabel creates UI Root camera
« Reply #2 on: July 21, 2016, 02:58:16 AM »
Ok thanks. It worked.