• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
4
Question by douglasg14b · Feb 22, 2015 at 08:33 PM · uiprefabparent

4.6 Newly Instantiated UI Prefabs Are Not Visible?

I'm trying to create button prefabs for some of my UI buttons and icons, however whenever I instantiate a new one from a prefab it's completely invisible.

If I drag and drop the prefab in the editor onto the scene it also goes in as invisible. Though, if I drag and drop it into the hierarchy under the panel it's supposed to sit under it shows up like normal. If I take the "invisible" object and drag it in the hierarchy under the appropriate parent it continues to be invisible. The same thing happens if I instantiate the object in code, and then assign it's parent to the appropriate panel via code, it remains invisible.

What is going on here, and how do I fix it?

Thanks!

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image zeppike · May 06, 2015 at 10:20 AM 0
Share

Firs you should check the Scale of your UI elements, it is possible, that they are as tiny they are not visible. If this is the case just use copy the scale of the parrent, or use Vector3.one, to start.

4 Replies

· Add your reply
  • Sort: 
avatar image
15

Answer by Dr-Nick · May 06, 2015 at 09:56 AM

I found I was having a similar problem when I was instantiating ui prefabs during an Awake() method upon starting the Application. I found the solution was to do the prefab instantiation in the Start() method instead. I imagine in my case, the UI objects would have been created before the canvas was ready for them and thus remained invisible during the application.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image TheLagbringer · Jul 20, 2015 at 10:29 AM 3
Share

Thanks a lot ! This answer definitely placed me in a good direction and I eventually worked it out. However I am not 100% sure if Start/Awake made the difference. I tried some combinations and while those two methods yielded a slightly different behavior (weird) the true deal breaker for me was using

 prefabInstance.transform.SetParent(panel.transform, false);

ins$$anonymous$$d of

 prefabInstance.transform.SetParent(panel.transform);
avatar image Lisurc · Jan 01, 2016 at 01:24 PM 0
Share

Definitely the answer I was looking for. I'm getting used to placing my initialization stuff in the Awake() method but in case of dynamically adding UI elements to a Scrollview/Content I had to switch to the Start() method. Thanks!

avatar image
1

Answer by MichalOp · Feb 22, 2015 at 08:43 PM

In editor you have to drop it to panel directly. In game, you should use Instantiate (yourPrefab,false); to instantiate UI elements and assign it to your panel.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

Answer by KazYamof · Jul 20, 2015 at 11:02 AM

All UI Components has to be children of a Canvas to be visible.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Michael_Berna · Oct 04, 2021 at 03:31 PM

Somehow, mine got a scale of zero when it instantiated and I didn't notice it. That may be worth checking.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

25 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Make a simple tree 1 Answer

Problem with prefab parent and children objects that need to be instantiated multiple times. 1 Answer

spawning object as child of other:error 2 Answers

Check for Same Image 0 Answers

Putting a variable of a child in the inspector for the parent 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges