Search Unity

Question Change AIM/BODY of FreeLook in runtime

Discussion in 'Cinemachine' started by xxflecsoxx, Dec 14, 2022.

  1. xxflecsoxx

    xxflecsoxx

    Joined:
    Apr 28, 2020
    Posts:
    12
    Hello! I need help with changing aim or body at component FreeLook through script. I found no answers in other topics...
    upload_2022-12-14_11-23-53.png
     

    Attached Files:

  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    It's not standard practice to be changing these things by script. Usually, in order to change the behaviour, you make a second FreeLook with the new settings and activate it, which causes the CMBrain to make a smooth blend. If you change programmatically, there will be a pop.

    Assuming that you don't care about the pop, the way to do it is to access the 3 rigs and change the behaviours in there, e.g. freeLook.GetRig(0).SetCinemachineComponent() etc.

    You can see examples of similar code in the Scripting sample scene that comes with Cinemachine.

    Note: you can only change the Aim this way. Changing the body will probably result in a crash.
     
  3. xxflecsoxx

    xxflecsoxx

    Joined:
    Apr 28, 2020
    Posts:
    12
    Hello! Thank you for quick response.
    It is a pity that there is no possibility of changing Aim through script.

    Thanks for the advice, I'll try to play around with two cameras.
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    You CAN change the Aim through script.