Search Unity

Set noise profile by script?

Discussion in 'Cinemachine' started by Permanent_AfterGlow, Dec 10, 2017.

  1. Permanent_AfterGlow

    Permanent_AfterGlow

    Joined:
    Nov 13, 2016
    Posts:
    6
    How to

    Change Noise none to Noise Basic Multi Channel Perlin.
    and
    Change Noise Profile to any of several that I have already created.

    via script?

    Thanks.
     
  2. JakubSmaga

    JakubSmaga

    Joined:
    Aug 5, 2015
    Posts:
    417
    I'm pretty sure this will work:
    Code (CSharp):
    1. using Cinemachine;
    2.  
    3.  
    4. public CinemachineBasicMultiChannelPerlin myNoiseProfile;
    5.  
    6.  
    7. CinemachineVirtualCamera vcam;
    8. vcam = FindObjectOfType<CinemachineVirtualCamera>();
    9. vcam.GetCinemachineComponent<CinemachineBasicMultiChannelPerlin>().m_NoiseProfile = myNoiseProfile;
     
    Adam_Myhill likes this.
  3. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    Almost but not quite. You have to use AddCinemachineComponent(new CinemachineBasicMultiChannelPerlin()); And then access it via the Get call to change the profile.
     
    Last edited: Dec 12, 2017
    JakubSmaga likes this.
  4. Permanent_AfterGlow

    Permanent_AfterGlow

    Joined:
    Nov 13, 2016
    Posts:
    6
    Should that be
    Code (CSharp):
    1. public NoiseSettings myNoiseProfile;
    and will it work at runtime?

    Thanks
     
  5. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    Yes and yes.
     
  6. Permanent_AfterGlow

    Permanent_AfterGlow

    Joined:
    Nov 13, 2016
    Posts:
    6
    I am still struggling with this, I have

    Code (CSharp):
    1. CinemachineVirtualCamera vcam;
    2. NoiseSettings mynoisedef = Resources.Load("Assets/Resources/First_Noise") as NoiseSettings;
    3.  
    4. vcam = sceneindex.gameObject.GetComponent<CinemachineVirtualCamera>();
    5. vcam.AddCinemachineComponent<CinemachineBasicMultiChannelPerlin>();
    6. vcam.GetCinemachineComponent<CinemachineBasicMultiChannelPerlin>().m_NoiseProfile = mynoisedef;
    7.  
    When I run it and select the vcam in the scene, I can see that it added the CinemachineBasicMultiChannelPerlin, but
    I don't see the profile selected there.

    Please help, thanks
     
  7. IgorDemchuk

    IgorDemchuk

    Joined:
    Mar 9, 2015
    Posts:
    21
  8. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    Try adding a debug statement to prove that mynoisedef is not null.
     
  9. Deleted User

    Deleted User

    Guest

    Is there a way to set the noise profile to any of the existing ones?
     
    TubbyYoungbros likes this.
  10. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    It's possible to use the AssetDatabase to load a preset (use "Packages/com.unity.cinemachine/Presets/Noise/..." in the path specification), but that is an editor-only thing. If you need it in the build, you'll have to clone the preset into your project and use that.
     
  11. narotuali

    narotuali

    Joined:
    Oct 23, 2018
    Posts:
    6
    any example of code to use that cause I want to do more than one noise
     
  12. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
  13. narotuali

    narotuali

    Joined:
    Oct 23, 2018
    Posts:
    6
    the example that i ask is about getting access to 6D shake noise by the script
    your way is to access to the noise that i have made i want to access to the default 6D shake
    yes I can set the noise to 6d shake by inspecter but when i went to switch it with another noise wave that i have made
    the code is switch and i get access to my noise wave that i had made but when i want to switch to 6D shake i don't know how to access to it thanks
    @Gregoryl
     
    Last edited: Apr 4, 2019
  14. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    I suggest that you clone the 6D shake into your assets, and then just access the clone in the normal way.
     
    MathewHI and narotuali like this.