Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Priority not working

Discussion in 'Cinemachine' started by adcasna, Mar 3, 2022.

  1. adcasna

    adcasna

    Joined:
    Jul 7, 2021
    Posts:
    7
    Hello I'm new using Cinemachine and I'm working in a local multiplayer game for class, when depending the number of players selected in a previous scene then the players prefab are instantiated and splits the camera.

    For each player I create a Cinemachine Brain and a Cinemachine virtual Camera and via script and then I split the camera.

    My problem is that the Live Camera of the Player 1 aims to the second player and changing the priority of the players or add each player to a different Layer and then ignore layers in the culling mask does nothing.

    I tried this tutorial but it doesn't work for me.



    If a disable the GameObject then the virtual Camera switches to Player 1 but doing this ends the game.

    Could you help me please?
     

    Attached Files:

  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,331
    I'm a little confused about what you're describing. Players don't have priority, so I don't understand what you mean when you say "changing the priority of the players". You shouldn't be putting the players on different layers, just the vcams.

    Conceptually, it's like this:
    1. Put all your players, and things that the cameras will render, on one or more "game content" layers. These layers are visible to all the cameras with the brains.
    2. Then, one special layer for the Player1 vcams. All player1 vcams belong to this layer and no other. Only Player1 Camera/Brain sees this layer (in addition to the "game content" layers).
    3. Then, another special layer for the Player2 vcams. All player2 vcams belong to this layer and no other. Only Player2 Camera/Brain sees this layer (in addition to the "game content" layers).
    Does that make sense?
     
    Last edited: Mar 3, 2022
  3. adcasna

    adcasna

    Joined:
    Jul 7, 2021
    Posts:
    7
    Thank you for your answer.

    I was meaning the priority of the virtual cameras that are child of the player Game objects.

    The virtual camera of player 1 belongs to the layer P1 Cam and the player 2 virtual cam belong to P2 Cam.
    Then the Camera of each player with de Cinemachine brain ignores the other player cam layers.

    But only if I disable the P2 Game object then the virtual Camera of the player 1 changes it's objective to the player 1.

    Really appreciate your help.
     

    Attached Files:

  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,331
    Normally you shouldn't make vcams children of the players. You can make them separate objects, children of a common parent in the prefab if you like.

    Your camera should see only P1 layer, not P3 and P4.

    Try putting all priorities to the same value. It's not clear to me why you need them at all. Each brain will find the active vcam on the layer that it can see.
     
    Last edited: Mar 8, 2022
    antoinecharton likes this.
  5. adcasna

    adcasna

    Joined:
    Jul 7, 2021
    Posts:
    7
    I ignored P3 and P4 layer from the culling mask but still not working.

    I put the priorities at the same value but nothing happens. I used it to try to make the P1 camera brain Live Camera get the Player 1 prefab. At this moment the Player 1 Live Camera it's aiming to the player 2 prefab like the first image I uploaded.
     
  6. adcasna

    adcasna

    Joined:
    Jul 7, 2021
    Posts:
    7
    I managed to fix my problem!

    The solution was indeed to stop making the virtual cameras children of the players, after that it still was necessary to use the priorities but it works.

    After that I modified the values of the virtual cameras via script and it looks perfect.

    Thank you so much for your help.
     
    Gregoryl and antoinecharton like this.