So far I love Cinemachine and Timeline! Now I’m trying to use them in a Multi-scene setup. Where there is ‘main’ scene with the main-camera, and sub-scenes containing individual levels.
The Playable director loses the references to the main camera bindings on play. I’ve read somewhere that it’s not fully supported yet.
So my question is, what would be the best approach for now?
And when it most likely will be supported?
@DavidSmit - Keeping references across scenes is a tricky situation. You can prefab the camera system up and dynamically load it into each scene as needed. We know about the cross-scene linking being an issue, it’s a known thing, for now try to avoid any cross scene references
Prefabs weren’t the way to go for me unfortunately.
For now I’ve managed to create a little script that fixes them. It only works for the first track, and if the binding is for the main-camera.
But for those who are running into similar problems (and are using timeline in a limited fashion), and where prefab isn’t an option, this works:
Camera _cam;
public void FixCinemachineBindings (PlayableDirector dir)
{
if ( dir == null )
return;
if ( _cam == null )
_cam = Camera.main;
Cinemachine.CinemachineBrain brain = _cam.GetComponent<Cinemachine.CinemachineBrain>();
TimelineAsset timelineAsset = (TimelineAsset) dir.playableAsset;
TrackAsset track = (TrackAsset) timelineAsset.GetOutputTrack(0);
dir.SetGenericBinding(track, brain);
}
using UnityEngine;
using UnityEngine.Playables;
using UnityEngine.Timeline;
using Cinemachine;
using Cinemachine.Timeline;
public class CineMachineAdvTrack : Cinemachine.Timeline.CinemachineTrack {
protected override Playable CreatePlayable(PlayableGraph graph, GameObject go, TimelineClip clip)
{
go.GetComponent<PlayableDirector>().SetGenericBinding(this, Camera.main.GetComponent<CinemachineBrain>());
return base.CreatePlayable(graph, go, clip);
}
}
The problem that is raised in this thread, i.e. that the Playable director loses the reference to the main camera when there is a scene change, has that been resolved in the lastest version of Unity?
I am having a similar issue trying to get Cinemachine to play nice with a multi-scene setup. I have an initial scene which loads with it’s own dedicated camera which I then want to put in charge of virtual cameras in each scene. This workflow doesn’t seem to be support though.
If the main camera with the CM brain stays loaded it will auto-detect any vcams that load dynamically, regardless of whether they’re in another scene. Timeline bindings, on the other hand, need to manually set as described above.
Can you give more details about your setup, what you’re trying to do, and what exactly isn’t working?
Setup
An initial scene which holds a main camera that is auto loaded through a bootstrap class.
In another scene I have an additional camera specifically for UI elements which are on a canvas in that scene. (Depth Only, Culling Mask UI, Ortographic)
The project is 2D and the cameras have a PixelPerfectCamera component.
Goal
What I am trying to handle is custom UI interactions where the user can drag around windows etc that remain pixel perfect. I’ve written a custom handler for the interactions that require a camera reference (hence the in-scene camera)
Issues
When using regular cameras this setup renders just fine.
Using both cinemachine cameras the UI doesn’t render at all.
Using a regular camera for UI doesn’t work initially but does work when I disable and re-enable the UI camera.
I doubt that the problem is related to Cinemachine. I suspect that there is some other issue that gets tripped inadvertently when you change to CM cameras. I can’t really say more than that without seeing the project.
For sure you shouldn’t be using Cinemachine for the UI camera. I don’t see what they would bring to the table for that use-case.
Thanks for the interest in the issue and confirming that I am on the right track. I’ll report back once I figure out what was causing it.
EDIT: Finally have it working consistently:
MainCamera (cinemachine brain) :
Main Camera Tag
Depth needs to be LOWER than the UI camera
Clipping Plane needs to be a negative number to not clip tilemaps
Culling Mask should NOT include the layer of the UI Camera
PixelPerfectCamera Addon required
UI Camera (non cinemachine):
Depth Only
Culling Mask ONLY UI layer
Depth needs to be HIGHER than Main Camera
PixelPerfectCamera Addon required
PixelPerfectCamera Upscale Render Texture required (Without this it just renders void)
Still unsure as to why Upscale Render Texture setting is required (would love to know why) but it seems to work now.
Hope this helps others with a similar issue in the future.