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 marcohills · Mar 20, 2015 at 01:20 PM · 2dprefabspritetext

Basic: Text sub-component of sprite prefab not showing

Hi guys,

I'm using Unity to develop a 2d game, and have a very basic question. I have a prefab which is made of a 2d sprite, which I instantiate like this:

Instantiate (GameResources.shared.prefab_tile, new Vector2 (x, y), Quaternion.identity) as GameObject;

That works and my sprite it displayed correctly. Now I need to display some dynamic text (a number) on top of the sprite. I tried adding a Text or GUIText component to the prefab, set its text (statically from the designer, to start with), font, color etc....all to no avail, the text just does not render.

I think I'm missing something very basic, but I've already wasted a couple of hours and scoured the web, without finding a solution :( Any help is greatly appreciated!

Comment
Add comment · Show 5
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 marcohills · Mar 19, 2015 at 09:33 PM 0
Share

btw, this happens even by just adding a sprite to the scene in the designer, adding the Text component and setting its properties => text does not appear

avatar image marcohills · Mar 19, 2015 at 10:27 PM 0
Share

I tried adding a Text$$anonymous$$esh as well, but it doesn't work because the editor tells me that the $$anonymous$$eshRenderer component conflicts with the existing SpriteRenderer.

So basically I tried adding a Text, GUIText and Test$$anonymous$$esh component to the sprite, and none worked for me...still not sure why...

avatar image AlwaysSunny · Mar 20, 2015 at 07:40 AM 0
Share

A Unity 4.6+ UI Text component requires a Canvas to render. This is probably what you should be using, as opposed to the alternatives you mentioned trying. Those alternatives are inferior to the Text component. The object must have a Text component, a Canvas Renderer component, and a RectTransform (plain Transform might work too? not sure). This object with those three components must be a child of a Canvas object.

Try creating a canvas and a text object via the editor GameObject menu and see if you can get that to show up. There are many factors in play here, and they've all got to be correct; luckily the built-in system for adding objects to the scene sets up most things automatically.

avatar image ZuPe2112 · May 21, 2015 at 06:15 AM 0
Share

Same problem here, did you find any solution? By the way, AlwaysSunny, adding a Text component or creating a Text GameObject automatically adds Canvas Renderer component and RectTransform component as well, but it doesn't solve the problem. As marcohills said, probably just something very basic is missing. :(

avatar image AlwaysSunny · May 21, 2015 at 08:43 AM 0
Share

This might be some kind of bug. I've since encountered an issue where duplicating objects with Text components in their hierarchy will cause the duplicate's Text component(s) to stop rendering. Nothing I can think of to try fixes them, and I've been required to duplicate such objects the "long way" by re-building them from scratch. Not sure if it's related, but seems to be. So far this issue hasn't affected any runtime-instantiated prefabs involving Texts, and is more of an annoyance than an emergency.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by ZuPe2112 · May 21, 2015 at 09:40 AM

I've finally found how to fix it:

First of all, i instantiated a new empty gameobject as a child of the prefab. Then i added a textmesh component to that gameobject (so the conflict with parent spriterenderer has been avoided). It was necessary to set z coord of the text to a value near to underlying prefab z coord value (if z value is too different, text will move on the sprite as the same sprite changes its position on the screen). After that, unfortunately, i experienced another problem: text was visible only when the sprite was on a certain part of the screen (it seemed like text was visible when sprite x coord was > 0). After some research, i've found that the problem was about the sprite shader (you can find it clicking on material): i created a new material, setting shader to Unlit -> Transparent/Cutout and replaced old material with the new one.

Everything seems to work fine now :)

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

2D Lighting Material Overlap Issues 4 Answers

Setting animator parameter on a single instance of a prefab sets the parameter for all instances 3 Answers

2D Draw text at sprite position with script only 1 Answer

Disfigured sprite after build. 0 Answers

Display UI Text on a 2D Sprite 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