Search Unity

  1. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  2. Want more efficiency in your development work? Sign up to receive weekly tech and creative know-how from Unity experts.
    Dismiss Notice
  3. Participate with students all over the world and build projects to teach people. Join now!
    Dismiss Notice
  4. Build games and experiences that can load instantly and without install. Explore the Project Tiny Preview today!
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  6. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Adding new Virtual Cameras at runtime

Discussion in 'Cinemachine' started by RobO_HB, Nov 27, 2018.

  1. RobO_HB

    RobO_HB

    Joined:
    Sep 16, 2013
    Posts:
    4
    Hello,

    I'm currently working on a title where the environments can be unpredictable (we don't have pre-made environments, they can be procedural and/or edited at runtime). I'm looking to set up cameras dynamically, via heuristics for picking a handful of good candidate positions as well as settings for framing various shots at particular times. I currently have a Cinemachine Brain set up, and I was thinking a Clear Shot camera makes a lot of sense for determining which virtual camera currently has the best shot to display. What I'm wondering:
    1. Is it possible to create new Virtual Cameras for my Clear Shot camera to manage entirely at runtime, rather than creating them ahead of time in the Scene? Is there an API for doing so (i.e. once I've created a gameobject for the VC and added the CinemachineVirtualCamera component, is there a way to "register" that with the Clear Shot camera)?
    2. If the answer to 1. is "yes", is doing so a reasonable practice? Or would it be better to create a collection of virtual cameras ahead of time (the maximum number I think I'd need at any given time), and then reuse them in each situation while disabling the cameras I don't need for that situation?
    Thanks,
    Rob
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    1,823
    ClearShot will manage all vcams that are parented to it.
    Have a look at the Script example scene in the CinemachineExamples package for code that creates vcams at runtime.
     
  3. RobO_HB

    RobO_HB

    Joined:
    Sep 16, 2013
    Posts:
    4
    Hi Gregory,

    Thanks for the info, the Scripting example is pretty close to what I was looking for, so I think I'm on the right track now.

    Rob