playMaker

Author Topic: Cinemachine Get Active Virtual Camera[SOLVED]  (Read 6406 times)

hoyoyo80

  • Full Member
  • ***
  • Posts: 136
Cinemachine Get Active Virtual Camera[SOLVED]
« on: September 01, 2019, 08:27:17 AM »
Hi all,

Ive in dire need to Get Active Virtual Camera, since i have multiple Virtual Camera in my game.

Beside, there a lot of actions that my require acces via PM like transposer offset etc.

Thanks
« Last Edit: October 18, 2019, 02:25:57 AM by jeanfabre »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Cinemachine Get Active Virtual Camera
« Reply #1 on: October 15, 2019, 09:25:59 AM »
Hi,

 Made an update featuring this action "VirtualCameraGetCurrentActive"

 it requires the CinemachineBrainProxy component to be in the scene next tot he cinemachine brain to work.

Please update from the Ecosystem. Let me know how it goes.

 also, ping me when you don't get any answers to your requests, it's likely that we just did not see it.

Bye,

 Jean

hoyoyo80

  • Full Member
  • ***
  • Posts: 136
Re: Cinemachine Get Active Virtual Camera
« Reply #2 on: October 17, 2019, 09:30:25 PM »
Phew...Thanks for the action. Ive use other method to get current active camera but it works. Before this i had lag when switching camera,sudden spike.After change to this action the spike gone 8) Thanks again

Christoph

  • Beta Group
  • Sr. Member
  • *
  • Posts: 254
Re: Cinemachine Get Active Virtual Camera[SOLVED]
« Reply #3 on: March 20, 2023, 03:09:32 PM »
Sorry for waking up this old thread. But I wrote this simple action that works perfectly fine for me. I believe the only downside is that it won't work if there's more than one cinemachine brain in the scene. But otherwise probably simpler to implement?

Code: [Select]
using UnityEngine;
using Cinemachine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory("Cinemachine")]
[Tooltip("Gets the current Live Camera (vCam) from the Cinemachine Brain component on the Main Camera and stores it as a GameObject Variable. Only works if there's a single Cinemachine Brain in the active Scene.")]

public class GetCinemachineLiveCamera : FsmStateAction
{
[Tooltip("The Game Object variable to store the current Cinemachine vCam")]
public FsmGameObject currentVCam;

public override void Reset()
{
currentVCam = new FsmGameObject { UseVariable = true };
}

public override void OnEnter()
{
//Get the Live vCam
var brain = CinemachineCore.Instance.GetActiveBrain(0);
currentVCam.Value = brain.ActiveVirtualCamera.VirtualCameraGameObject;

Finish();
}
}
}

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Cinemachine Get Active Virtual Camera[SOLVED]
« Reply #4 on: March 21, 2023, 05:35:24 AM »
Hi.

if on

Code: [Select]
var brain = CinemachineCore.Instance.GetActiveBrain(0);
instead of 0 , and a fsmInt index so you can set a index value on the action

on reset you can set : index.Value = 0;

Christoph

  • Beta Group
  • Sr. Member
  • *
  • Posts: 254
Re: Cinemachine Get Active Virtual Camera[SOLVED]
« Reply #5 on: March 21, 2023, 11:32:52 PM »
That would be if you have different brains in the same scene? How you know though with index is which brain?

And does that mean my action is legit? 😛

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Cinemachine Get Active Virtual Camera[SOLVED]
« Reply #6 on: March 22, 2023, 01:52:26 AM »
Hi.
I never used Cinemachine yet :)

if required you could create an action to compare a 'brain' to get the index.
if you need a certain brain

on your current action you can add the variable and set default to 0
so you can at least set an index :)

Christoph

  • Beta Group
  • Sr. Member
  • *
  • Posts: 254
Re: Cinemachine Get Active Virtual Camera[SOLVED]
« Reply #7 on: March 23, 2023, 01:09:51 PM »
Here you go. That should be it then:

Code: [Select]
using UnityEngine;
using Cinemachine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory("Cinemachine")]
[Tooltip("Gets the current Virtual Live Camera from the Cinemachine Brain component of your Camera and stores it as a GameObject Variable. Alternatively, you can set the index of the Brain in case you have more than one in your scene.")]

public class GetCinemachineLiveCamera : FsmStateAction
{
[Tooltip("Set the index of the Cinemachine Brain. If your scene only has 1 brain, then the index is 0.")]
public FsmInt brainIndex;

[Tooltip("Set the Game Object variable to store the current Cinemachine Virtual Camera.")]
public FsmGameObject currentVCam;



public override void Reset()
{
brainIndex = 0;
currentVCam = new FsmGameObject { UseVariable = true };
}

public override void OnEnter()
{
//Get the Live vCam
var brain = CinemachineCore.Instance.GetActiveBrain(brainIndex.Value);
currentVCam.Value = brain.ActiveVirtualCamera.VirtualCameraGameObject;

Finish();
}
}
}

You're missing out by not using Cinemachine djaydino!

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Cinemachine Get Active Virtual Camera[SOLVED]
« Reply #8 on: March 24, 2023, 03:00:04 AM »
Hi.
nah, i'm using a different 3rd party tool for our game.
which fits very well for 2d