Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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
0
Question by username707 · Sep 25, 2013 at 05:09 PM · spritengui

NGUI Sprite not visible in 3d when added by code

When i add them by hand its nice two-sided GO with sprites, but when i do this by code

 GameObject squadUnit = new GameObject("squadUnit"+i);
 UISprite uiSpr = squadUnit.AddComponent<UISprite>();
 uiSpr.atlas = atlas;
 uiSpr.spriteName = "frame2";
 uiSpr.panel = uiPanel;
 squadUnit.transform.parent = panel.transform;
 UISpriteAnimation uiSprAnim = squadUnit.AddComponent<UISpriteAnimation>();
 uiSprAnim.framesPerSecond = 8;
 uiSprAnim.namePrefix = "frame";

I see a rectangles but animation frames not visible How to add them properly?

alt text

alt text

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 vexe · Oct 05, 2013 at 10:12 AM 1
Share

Are you still stuck with the problem? How did it go?

2 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by vexe · Oct 02, 2013 at 11:53 PM

You're probably having parenting issues with your widgets and panel.

Instead of having to worry about parenting, let NGUI do it for you, use NGUITools.AddChild:

 GameObject squadUnit = NGUITools.AddChild(uiPanel.gameObject, new GameObject("squadUnit"+i)); // this will create the object and parent it properly
 UISprite uiSpr = squadUnit.AddComponent<UISprite>();
 uiSpr.atlas = atlas;
 uiSpr.spriteName = "frame2";
 //    uiSpr.panel = uiPanel;                          don't need that no more
 //    squadUnit.transform.parent = panel.transform;   nor that

And btw, sometimes widgets don't appear even if you add them manually in-scene, if that happens just pull your panel a little bit forward. See this for more info as to why this happens (it's a Unity thing)

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 username707 · Oct 05, 2013 at 07:34 PM 0
Share

Not sure if i will have the chance to check this solution, as i have moved to 2dtoolkit for sprites. Still have the feeling this might be just the thing to get them going on NGUI. Thanks.

avatar image vexe · Oct 06, 2013 at 05:26 AM 0
Share

I $$anonymous$$gest you move back to NGUI 3.0 - As the new UnityGUI will be based on NGUI, that way your migration will be easy. See this.

avatar image
0

Answer by whydoidoit · Oct 05, 2013 at 11:39 AM

It's probably not on the right layer to be rendered by the camera that is doing the NGUI stuff. That's normally what it is when it happens to me :)

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

17 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

Related Questions

Load sprites from NGUI atlas and display them on scene 0 Answers

NGUI Slider foreground color change 1 Answer

how to change sound option sprite when clicked 0 Answers

NGUI button: Different sizes for different states? 0 Answers

NGUI Texture atlas help ! 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