I have a state driven camera that switches camera setups according to the player’s animation state. Is there a way to switch vcams based on a collider trigger? The player’s animation might not change, but I’d like to change the camera setup for certain parts of the game.
Within the SDC, no, but you could have another vcam and activate that from your trigger. The SDC would just blend to that, and it would blend back when your override vcam deactivates.
Use vcam.gameObject.SetActive() to toggle its active status.
This activates/deactivates the vcam. The Unity camera will become aware of it automatically because of its CinemachineBrain component.
Can you show me a picture of the inspector for your CinemachineBrain?
In particular, I want to see whether you have custom blend rules that would produce the result you’re seeing.
I think i figured it out – When I created the new Virtual Camera, at some point I wound up with a Camera component and a Cinemachine Brain. When I disabled these two components it seems to work. Not sure how the extra camera and brain got in there tho - here’s a screenshot:
I have noticed something else. If I put the newly created Virtual Camera into the CM StateDrivenCamera object (along with the other cameras), I can’t seem to reference it from my trigger script. If it’s outside of the group, then I can. See image (vcam4 specifically).
Are you creating these vcams using the Cinemachine menu in the editor, or are you doing it by script? I ask because it’s very peculiar to be getting these extra brains and Camera components. It’s a good idea to clean them up, or general confusion will result.
Your scene should have a single camera with a brain component. Delete all the others (remove them, don’t just deactivate).
The way the State-Driven-Camera works (also ClearShot, MixingCamera, and other “meta-camera” manager vcams) is that they manage their vcam children and hide them from the outside world. Their children become a kind of private vcam army, that they manage. Parenting vcam4 under the SDC effectively enrolls vcam4 in the SDC’s private army - which you don’t want to do. Keep it outside, where it belongs.
That said, nothing stops you from organizing your vcams in container objects for neatness, but be aware that vcams parented to other vcams has a special meaning in Cinemachine. Don’t do it without just cause.
Cinemachine now comes with a handy CinemachineTriggerAction helper script. Attach it to your collider and then you can use it to activate/deactivate vcams, play timelines, trigger events, and other things, all without having to code.
On my Trigger Zone, I have a Box Collider with Trigger bool checked. Regarding to this post https://discussions.unity.com/t/769291 , I also added a Rigidbody with Gravity unchecked.
On my SDC, I made an EaseIn/Out transition when switching between the TriggerCam and the GameplayCam. But there are no transition happeing on entering/exiting the Trigger zone.
Thanks for the quick reply. Unfortunately, it does not. I removed VCAM_HOUSE_CloseUp from the SDC hierarchy and expected to switch from CM_ThirdPerson_FreeLook to it when entering the trigger zone, but nothing happens.
Also, let’s say it did work. How then will it be possible to blend between those two cameras without having them under the same SDC? (Sorry if it’s a newbie question, I’m freshly starting with SDC).
Maybe it’s a priority thing. Put VCAM_HOUSE_CloseUp at a higher priority that the SDC, then when it’s activated it will become dominant.
As for blends, it’s the job of the CM Brain (on the main camera) to take care of blending between the vcams. When a new vcam is activated with sufficient priority, the brain will apply its default blend to the transition (unless you have a custom blend defined for this one).
I get the sense that in your project the SDC is unnecessary. If your default vcam is the FreeLook, and you want to activate other vcams in response to game events, then you should not be using the SDC. Just leave the FreeLook loose, like VCAM_HOUSE_CloseUp. The SDC is for mapping vcams to animation states.
For example, if your default FreeLook had different settings depending on what the player is doing (walking, running, etc) then you could have multiple FreeLooks parented to the SDC, each with slightly different settings, with instructions to map them to specific animation states of the player. The SDC would blend between them based on the animation state. The whole thing would look like one vcam to the brain, which would then blend into or out of this complex thing very simply.
I took your advice and tried a different approach. I stopped using SDC beacause as you said, as it is only for animation states mapping, I woulf have been stucked at a certain point with this limit. I can’t find the post, but someone suggested to have a simple list containing all my Vcams on a parent node under which they are and call them individually and when needed by index. This indeed works perfectly for me.
I’m really loving Cinemachine right know due to this