Playmaker Forum

PlayMaker Feedback => Action Requests => Topic started by: hoyoyo80 on September 01, 2019, 08:27:17 AM

Title: Cinemachine Get Active Virtual Camera[SOLVED]
Post by: hoyoyo80 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
Title: Re: Cinemachine Get Active Virtual Camera
Post by: jeanfabre 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
Title: Re: Cinemachine Get Active Virtual Camera
Post by: hoyoyo80 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
Title: Re: Cinemachine Get Active Virtual Camera[SOLVED]
Post by: Christoph 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();
}
}
}
Title: Re: Cinemachine Get Active Virtual Camera[SOLVED]
Post by: djaydino 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;
Title: Re: Cinemachine Get Active Virtual Camera[SOLVED]
Post by: Christoph 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? 😛
Title: Re: Cinemachine Get Active Virtual Camera[SOLVED]
Post by: djaydino 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 :)
Title: Re: Cinemachine Get Active Virtual Camera[SOLVED]
Post by: Christoph 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!
Title: Re: Cinemachine Get Active Virtual Camera[SOLVED]
Post by: djaydino 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