Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

World Space Canvas in a Prefab

Discussion in 'Prefabs' started by jason_sone, Feb 4, 2019.

  1. jason_sone

    jason_sone

    Joined:
    Jul 7, 2017
    Posts:
    8
    Hi. New developer here with a question. I don't know if this has already been asked, but after 2 days of searching various phrases, I thought I'd bring my question here. I have a prefab with a video player component placed on a quad. I want to add play/pause controls (I already have the script, so no help needed there). I'd like the controls to appear over the video quad, which makes me think I need to render the canvas in world space. However, it requires a camera and my main camera is not a part of the prefab. How can I place a world space canvas in a prefab like this? For what it's worth, this is for an image detection scene using ARKit and ARCore.

    If this question has already been answered, a link would be welcome and I apologize for the duplicate question.

    I'm using 2018.3.4f1.

    Thanks!
     
  2. runevision

    runevision

    Unity Technologies

    Joined:
    Nov 28, 2007
    Posts:
    1,838
    If there is an instance of the Prefab in the scene at edit time, assign the camera there so it becomes an override.

    If the Prefab is instantiated at runtime, have the script which instantiates the Prefab also assign the camera to the Canvas.
     
  3. AndreiMarian

    AndreiMarian

    Joined:
    Jun 9, 2015
    Posts:
    44
    Facing the same issue. @runevision Thank you! But for the future, the idea behind prefabs is on one hand instantiating multiple instances of them and on the other, doing it at runtime. And world space canvases not so uncommon in games.
    Now 90% of the games only use one main camera so I'm thinking it would be a nice idea if there was an option to having by default assigned to "main camera at start".
    EDIT:
    <strike>I made the camera GO into a prefab and so I could assign it into the prefab of Canvas Event camera field in Inspector.</strike> It doesn't work.
     
    Last edited: Aug 5, 2020
  4. tgaldi

    tgaldi

    Joined:
    Oct 28, 2015
    Posts:
    87
    My menu prefab(s) have a canvas that I would like to set as screenSpaceCamera. Unfortunately if I don't assign a camera to the canvas in the prefab, even though I've set the render mode to screenSpaceCamera, it defaults to screenSpaceOverlay. At runtime I want to be able to check if the render mode of a menu's canvas is set to screenSpaceCamera, so that I can assign a camera to it when opening it, but its defaulted to overlay.
     
unityunity