playMaker

Author Topic: Accessing Playmaker Variables/Global Variables through C# Script  (Read 1083 times)

JumpJets

  • Playmaker Newbie
  • *
  • Posts: 4
Accessing Playmaker Variables/Global Variables through C# Script
« on: December 18, 2021, 06:32:17 PM »
Hi guys,

I am trying to access a Global Variable on an FSM from a C# script on the same object and I've hit a dead end. I just don't know what to do here. Could someone post some generic code for me? Thank you.

Jump Jets

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 4255
  • Official Playmaker Support
    • LinkedIn
Re: Accessing Playmaker Variables/Global Variables through C# Script
« Reply #1 on: December 20, 2021, 02:37:27 PM »
There are a couple of ways to get global variables:

Code: [Select]
var myBoolVar = PlayMakerGlobals.Instance.Variables.FindFsmBool("myBoolVar");
var myFloatVar = FsmVariables.GlobalVariables.FindFsmFloat("myFloatVar");

There are equivalent methods for each variable type.
It's good idea to store the variable if you're going to access it frequently (instead of calling FindXXX every time).