Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Request: publicly provide camera creation functions

Discussion in 'Cinemachine' started by Koltes, May 21, 2019.

  1. Koltes

    Koltes

    Joined:
    May 3, 2014
    Posts:
    5
    Hi,

    I want to provide my users with a custom window, including buttons to create virtual cameras. I also want to make additional logic, e.g. moving the created camera somewhere specific in the hierarchy. Sadly as of writing (2.2.8), Cinemachine.Editor.CinemachineMenu is internal, moreover the creation functions are private. So I'd have to duplicate this code.

    Could you please consider moving the logic of creating cameras in a new public utility class, whose functions would return the created game object?

    Thanks
     
  2. Koltes

    Koltes

    Joined:
    May 3, 2014
    Posts:
    5
  3. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
    I suggest you just duplicate the code. It's pretty standard stuff: creating game objects, naming them, and adding behaviours. Once we make things public, it's a commitment to maintaining the exact behaviour, and documenting it.
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
    You can also look at the CinemachineExamples/Scripting sample, which shows how to create and configure vcams from script.

    Consider also setting up prefabs and instancing them.
     
  5. Koltes

    Koltes

    Joined:
    May 3, 2014
    Posts:
    5
    I understand the problem with releasing publicly. Well, if I duplicate the code and you change the regular behavior, then I'm good for maintaining it too. Besides, I take for granted that public user interfaces should allow automation, i.e. run public functions, in order to build a pipeline around.

    As an alternative, you could trigger an event, notifying that some game objects (e.g. a virtual camera and a dolly track) have been created. That's more or less what I'm doing now by listening to EditorApplication.hierarchyChanged, but it's less accurate. In this case, you could keep the creation functions private, so there's no pressure to maintain the behavior.
     
  6. Koltes

    Koltes

    Joined:
    May 3, 2014
    Posts:
    5
    Indeed, the Scripting example is very lean. However, it is still duplication, relying also on Undo, SceneView.lastActiveSceneView.pivot, Selection, etc. Moreover, the menu will still be there, so I have no guarantee that a user will use my button instead of the menu.