Search Unity

Cinemachine Confiner 2D update area

Discussion in 'Cinemachine' started by Nazarick, Jan 31, 2018.

  1. Nazarick

    Nazarick

    Joined:
    Jan 29, 2014
    Posts:
    27
    Hello,

    In my scene I would like to use several Confiner2D. I tried to change the collider that serves as a reference to confine but it bug, I tried disabling the GameObject, change the collider and reactivate the GameObject, but still nothing.

    Looks like the Confiner keeps the coordinates in memory and it's not possible to change the containment zone to runtime.

    I keep trying a lot of little things but I can not find, would you have any idea?

    I am looking to make a dynamic change because in a single scene I can have 2 different confines up to 10 for evolution in the game level.

    I am interested in any idea. I thought of doing several cameras but I find it so heavy as a process.

    In advance I thank you for your help.

    Cordially
    Mr Nazarick
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    2,725
    Yes the 2D confiner caches the path shape, for performance. When you change the path, call confiner.InvalidatePathCache() to rebuild the cache.
     
    JUSTCAMH, jaxas, sandolkakos and 4 others like this.
  3. Nazarick

    Nazarick

    Joined:
    Jan 29, 2014
    Posts:
    27
    Thank you very much. It works perfectly!
     
  4. lumbryga

    lumbryga

    Joined:
    Feb 28, 2018
    Posts:
    5
    That's exactly what I was looking for and it works now! Thanks!

    As a side question (not sure if I should make another topic or not, as the title of this one is broad enough): The camera changes abruptly with this method. How can we change the camera location smoothly, in a way that it kind of "sweeps/moves" to the new location, instead of "teleporting", with Cinemachine? (Imagine a Metroid camera that moves when you change rooms; or, better yet, Hollow Knight, when you find a secret area).

    As an example:
    (from 0:18 to 0:25), he activates a trigger collider, so the camera confiner changes, and the camera moves smoothly to its new location, instead of "teleporting".

    Thank you!
     
  5. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    2,725
    @lumbryga The secret is to use the #1 rule of Cinemachine: Don't try to do it all with one vcam.
    Set up 2 vcams, one for each room, each with its own confiner shape. When it's time to switch rooms, activate the second vcam, and the camera will blend smoothly to it.
     
    Civetdelapin likes this.
  6. lumbryga

    lumbryga

    Joined:
    Feb 28, 2018
    Posts:
    5
    Ok, now it works perfectly! Just to register it for future reference, this is what I've done to achieve a Hollow Knight-like secret-found camera, updating the 2D Confiner Area with blend:

    I added to my scene only one CinemachineBrain GameObject, and two (in this case) Virtual Cameras GameObjects, identical in its properties but with different confiners (this was all done in the editor, and inspector, no scripts). Then, I selected the virtual camera with the first confiner I wished to use and, in the Inspector, clicked the "Solo" button, so it's Status changed to Live.

    Then, in the script of my trigger, i simply added the following (in its proper places, following good practices):

    Code (CSharp):
    1. GameObject cam;
    2. GameObject secretCam;
    3.  
    4. cam = GameObject.Find("FollowCam");
    5. secretCam = GameObject.Find("SecretCam");
    6. secretCam.SetActive(true);
    7. cam.SetActive(false);
    , where FollowCam is the name of the current virtual camera GameObject in the Hierarchy and SecretCam is the name of the virtual camera GameObject I want to change into.

    Finally, it was all a matter to change the blend settings in the Inspector of the CinemachineBrain object.

    Didn't even had to use
    confiner.InvalidatePathCache()
    !


    Thank you very much, Gregoryl! You rock!!
     
    oroborous and Civetdelapin like this.
  7. Jean-Fabre

    Jean-Fabre

    Joined:
    Sep 6, 2007
    Posts:
    331
    Hi,

    Do you need to call for confiner.InvalidatePathCache() when you change m_BoundingVolume as well?

    Bye,

    Jean
     
  8. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    2,725
    Only the 2D version of the confiner uses the path cache, so you don't have to invalidate it when you change m_BoundingVolume.
     
  9. Jean-Fabre

    Jean-Fabre

    Joined:
    Sep 6, 2007
    Posts:
    331
    ok, thanks :)

    Bye,

    Jean
     
  10. jaxas

    jaxas

    Joined:
    Mar 22, 2009
    Posts:
    57
    Thanks Gregoryl, exactly what i needed!
     
    Gregoryl likes this.
  11. RisingMos

    RisingMos

    Joined:
    Aug 28, 2015
    Posts:
    17
    Is there any issues related to this 2019.2.0f1? (Cinemachine version 2.3.4). I just spent the whole day trying to have InvalidatePathCache update the path with no success. I tried putting the code everywhere including awake, start, and update. I tried polygon collider and composite colliders. The collider works perfectly when inserted manually in the editor even while the game is playing. Any ideas for debugging it? Thanks!
     
  12. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    2,725
    We're not aware of any issues that would explain what you're seeing. Can you make a small demo project that shows this problem and send it to me?
     
  13. RisingMos

    RisingMos

    Joined:
    Aug 28, 2015
    Posts:
    17
    OK. I ended up creating the test project and it worked which puzzled me.

    I just figured the problem out. It turned out that the collider that I provided was the prefab collider, not the instance collider. Cinemachine definitely does not like that. Once the instance collider was provided, it worked perfectly.

    Thanks!
     
    Gregoryl likes this.