Search Unity

Is it possible to hide an object from certain cameras without layers?

Discussion in 'General Graphics' started by antony_morar, Jun 29, 2020.

  1. antony_morar

    antony_morar

    Joined:
    Nov 7, 2017
    Posts:
    12
    Case: FPS multiplayer, you have 2 meshes, the FPV and the TPV, want to hide the 3rd person mesh but other players use the layer
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    Is this networked multiplayer or couch multiplayer? If it's networked, then you shouldn't need layers. Just have the client code only enable the game object / renderer components you need for that client and don't sync them directly.

    If it's couch multiplayer, then you'll probably want to use layers. Alternatively you could manually disable / enable renderer components per camera using scripts that trigger from
    Camera.OnPreCull
    or
    Camera.OnPreRender
    . Note, that's a capital
    On
    , not lower case
    on
    .
    Camera.onPreCull
    is a delgate you can use that fires for all cameras, where as
    Camera.OnPreCull
    is a function that gets called only on script components attached to a game object with a
    Camera
    component, and only get called when that specific camera is about to render.