Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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
1
Question by Naphier · Oct 23, 2016 at 02:48 AM · uibillboarding

Billboard world space text

We have fairly large scenes generated from data files. In the scene there are multiple static objects with labels on them (TextMesh). Currently we're doing a lookat operation to make them face the camera and a distance operation to make them scale with the camera distance. The camera is able to move with complete freedom.

I'm looking for ideas on how to improve this as the distance operation is killing our FPS and the rotation is too. We'd like the text to always be the same size and always be facing the camera. It seems like an overlay UI would be good for this, but I don't know how we would fix the UI in world space but always have the labels in the proper position and face the camera. A bit of a conundrum.

Thanks!

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
3

Answer by Namey5 · Oct 23, 2016 at 05:46 AM

It sounds like what you are trying to achieve would be easily doable through a world-space positioned GUI element.

 //A C# example
 void OnGUI ()
 {
     Vector2 worldPoint = Camera.main.WorldToScreenPoint (transform.position);
     GUI.Label (new Rect (worldPoint.x - 100, (Screen.height - worldPoint.y) - 50, 200, 100), "Text to display.");
 }

You would just attach this script to every object that would have text, and in combination with the [ExecuteInEditMode] attribute it would work in practically all scenarios. This example works based off the "Main Camera" tagged camera but you can replace all elements in this to your needs.

Comment
Add comment · Show 7 · 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 Naphier · Oct 23, 2016 at 07:58 AM 0
Share

Thanks, not sure why I've been avoiding this, but looks like it is likely the simplest solution. I'll give it a go and report back.

avatar image Naphier · Oct 30, 2016 at 05:36 AM 0
Share

O$$anonymous$$, so I tested this out in an isolated project and it's almost working with a couple drawbacks.

  1. Our objects can easily be overlapping. Do you have any suggestions on how to deal with depth of both the GUI label and meshes? There will often be the case that a mesh should or label should be drawn behind. There are many "layers" of this.

  2. Is there a good way to ensure these are always drawn behind imGUI or do I need a separate camera for the imGUI that always renders on top?

Thanks!

avatar image Namey5 Naphier · Oct 30, 2016 at 05:43 AM 0
Share

If you are attaching this script to many objects, then you can use the GUI.depth variable to stack them manually, i.e.

 public int depth = 0;
 
 void OnGUI ()
 {
     GUI.depth = depth;
 
     ...

I'm not sure what you mean by 'mesh'. Are you using text meshes? As for the imGUI, I'll be perfectly honest and say that I've never used a combination of the 2 in any one project, so I'm not entirely sure. I'll do some research onto that and get back to you.

avatar image BeschterTopfMann · Nov 18, 2018 at 09:14 AM 0
Share

Thank you for that super easy answer <3

avatar image SamuelRoos · Nov 21, 2018 at 04:55 PM 0
Share

I strongly recommend to use Camera.current ins$$anonymous$$d of Camera.main for performance reasons.


Camera.main uses FindObjectWithTag and if that's called every frame it's very performance consu$$anonymous$$g. Also, a benefit with Camera.current is that it takes the current camera that is rendering, so no need to worry about tags.

avatar image Leoul SamuelRoos · Jun 18, 2020 at 04:20 AM 0
Share

Agreed that Camera.main has performance issues and the reference to the camera should be gotten by other methods, but Unity's documentation does not recommend using Camera.current outside of very specific overrides, which do not include OnGUI: https://docs.unity3d.com/ScriptReference/Camera-current.html

avatar image Namey5 Leoul · Jun 18, 2020 at 04:35 AM 0
Share

Camera.current is just a pointer to the most recent camera to render, so there isn't really a performance impact in using it and chances are it would be setup properly for OnGUI (I can't remember if I$$anonymous$$GUI is drawn per camera or just drawn straight into the final rendertarget). If you needed to, you could just cache Camera.main on first call and use it from there;

 Camera cam;
 
 void OnGUI ()
 {
     if (!cam)
         cam = Camera.main;
 
     ...

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

88 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 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 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 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

How to per-camera billboard World Space UI Canvas? 0 Answers

How to get IsPointerOverGameObject(touchID) object reference 0 Answers

Menu not getting Keyboard Input 0 Answers

Nested Content Size Fitters 1 Answer

How to add live background of your game to your main menu? 0 Answers


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