playMaker

Author Topic: Send Event from C# script on Prefab to Scene Game Object  (Read 784 times)

Christoph

  • Beta Group
  • Sr. Member
  • *
  • Posts: 254
Send Event from C# script on Prefab to Scene Game Object
« on: November 30, 2022, 10:10:49 AM »
I normally use Playmaker Utils to send events from a script to a FSM but it's the first time I need to do this from within a prefab. I have no clue how to do that though.

This is what I do:
PlayMakerUtils.SendEventToGameObjectFsmByName(null, gameObject, "FSM Name", "Event Name", null);

But how can I send it to a game object that I can't drag into the slot in the inspector? Do I have to search for it throughout the entire scene or could I conveniently access it as a global variable?

Thanks,
Christoph
« Last Edit: November 30, 2022, 01:21:15 PM by Christoph »

drown

  • Junior Playmaker
  • **
  • Posts: 58
Re: Send Event from C# script on Prefab to Scene Game Object
« Reply #1 on: December 08, 2022, 08:57:49 AM »
On the gameObject that is intended to receive you could use a "GetOwner" to store itself as a global PM GameObject variable - I have never used Playmaker from script though, just the other way around :b .

Christoph

  • Beta Group
  • Sr. Member
  • *
  • Posts: 254
Re: Send Event from C# script on Prefab to Scene Game Object
« Reply #2 on: December 08, 2022, 09:36:08 AM »
Yes, I'm actually using those managers as global variables already. Can I access Playmaker Global Variables directly from a C# script?

drown

  • Junior Playmaker
  • **
  • Posts: 58
Re: Send Event from C# script on Prefab to Scene Game Object
« Reply #3 on: December 08, 2022, 06:15:06 PM »
In the Playmaker API reference I found this:

Quote
Accessing Global Variables:

Use the static GlobalVariables property:

FsmFloat globalVar = FsmVariables.GlobalVariables.FindFsmFloat("myFloat");
globalVar.Value = 100;

Source: https://hutonggames.fogbugz.com/default.asp?W1103

Christoph

  • Beta Group
  • Sr. Member
  • *
  • Posts: 254
Re: Send Event from C# script on Prefab to Scene Game Object
« Reply #4 on: December 08, 2022, 06:29:42 PM »
hmmm interesting. This seems for actions though, rather than C# scripts. Maybe Djaydino could confirm. But this is really good to know either way. Thanks for sharing.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Send Event from C# script on Prefab to Scene Game Object
« Reply #5 on: December 09, 2022, 11:08:01 AM »
Hi.
It looks like its for C# scripts but I can not confirm.

I only use gameobjects in my globals.
Recently I setup a 'globals' Scriptable Object where I can get access directly to the fsms / gameobjects I have stored there from C# scripts.
(and made some custom actions to place the fsms/gameobjects into the global scriptable object)

drown

  • Junior Playmaker
  • **
  • Posts: 58
Re: Send Event from C# script on Prefab to Scene Game Object
« Reply #6 on: December 09, 2022, 11:11:04 AM »

Christoph

  • Beta Group
  • Sr. Member
  • *
  • Posts: 254
Re: Send Event from C# script on Prefab to Scene Game Object
« Reply #7 on: December 09, 2022, 11:32:00 AM »
ah damn, this is very nice. It doesn't show about the globals, but this is great otherwise. Actually, this is even better than Playmaker Utils.

And rises the question: if this exists like this, why do we need Playmaker Utils at all? Awesome!

Regarding your previous post, I will check that as well more on detail. Thanks also djaydino for your reply too.