Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
3
Question by lsdrambo · Mar 12, 2017 at 06:07 PM · uimultiplayerbillboardworld spacesplit-screen

World Space UI facing multiple Cameras (Billboard)

I'm working on a split screen multiplayer game. I have many world space UI canvas always facing the camera (billboard). I have a hard time making them face both cameras at the same time.

I tried to rotate the canvas to face the cameras using Camera.onPreCull and Camera.onPreRender callbacks. The object do receive the callback from both cameras every frame, but only the rotation from the last camera to be rendered seems to affect the UI object. If I replace the object for a standard 3D plane with a MeshRenderer, everything works as expected, ie the plane faces both cameras. I also tried OnWillRenderObject but it doesn't work as it needs to be attached to a gameObject with a Renderer, which is not the case for a Canvas.

Here is my camera facing script:

 public class LookAtCamera : MonoBehaviour
 {
     void OnEnable() { Camera.onPreRender += PreRender; }    
     void OnDisable() { Camera.onPreRender -= PreRender; }    
     void PreRender(Camera cam)
     {
         transform.LookAt(transform.position + cam.transform.rotation * Vector3.forward,
                          cam.transform.rotation * Vector3.up);
     }
 }

I ran out of solutions and I implemented a workaround by duplicating Canvas for each cameras using camera specific layers on each of them:

 public class DuplicateGameObjectOnMultipleLayers : MonoBehaviour
 {
     [SerializeField]
     LayerMask layers;
 
     bool first = true;
 
     void Start()
     {
         for(int i = 0; i < 32; i++)
         {
             if(((1 << i) & layers) != 0)
             {
                 if(first)
                 {
                     gameObject.layer = i;
                     first = false;
                 }
                 else
                 {
                     var newGameObject = (GameObject)Instantiate(gameObject, transform.position, transform.rotation, transform.parent);
                     newGameObject.gameObject.layer = i;
                     newGameObject.GetComponent<DuplicateUIOnMultipleLayers>().enabled = false;  //Avoid infinite recursion
                 }
             }
         }
     }
 }

I had to modify the LookAtCamera scripts to apply rotation only for cameras that renders the object's layer:

 public class LookAtCamera : MonoBehaviour
 {
     void OnEnable() { Camera.onPreRender += PreRender; }    
     void OnDisable() { Camera.onPreRender -= PreRender; }
 
     void PreRender(Camera cam)
     {
         if((cam.cullingMask & (1 << gameObject.layer)) != 0)
         {
             transform.LookAt(transform.position + cam.transform.rotation * Vector3.forward,
                              cam.transform.rotation * Vector3.up);
         }
     }
 }

Clearly not the best solution.

Does anyone know how to have a world space UI canvas facing multiple camera at the same time without duplicating it?

Comment
Add comment · Show 3
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 koval832 · Jul 02, 2017 at 08:53 AM 0
Share

@lsdrambo Hey! Did you find more elegant solution? :) Also ran into the same issue. Thanks.

avatar image lsdrambo koval832 · Oct 04, 2017 at 07:12 PM 0
Share

No, I'm still using the "duplicating canvas solution" ...

avatar image Bip901 · Nov 18, 2017 at 11:27 AM 0
Share

I have this problem as well. I'll try the double canvas solution...

0 Replies

· Add your reply
  • Sort: 

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Restricting Canvas navigation for each player 0 Answers

Mobile Multiplayer touch controls 0 Answers

Splitscreen w/ different GUIs on each camera 2 Answers

How to make a split-screen? (2 cameras rendering at same time) 4 Answers

all ui buttons applying to player 1, how do i make them apply to the player that clicked 2 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