playMaker

Author Topic: Best way to communicate with C# scripts?  (Read 1595 times)

hyperhuzaifa

  • Playmaker Newbie
  • *
  • Posts: 9
Best way to communicate with C# scripts?
« on: August 04, 2020, 07:17:45 AM »
Wondering if there is an event dispatcher system which works with playmaker.

Don't feel comfortable using Get/Set Property and Call Method actions due to use of reflection on IL2CPP.

nuFF3

  • Beta Group
  • Junior Playmaker
  • *
  • Posts: 74
  • Are we even real?
    • One Month Studio
Re: Best way to communicate with C# scripts?
« Reply #1 on: August 04, 2020, 09:22:36 AM »
Whenever I need to communicate with C# scripts, I just have them set up in a way that I can easily use Get/Set Property.
Public variables should work fine I suppose.
I haven't toyed around with more complex stuff.

Thore

  • Sr. Member
  • ****
  • Posts: 480
Re: Best way to communicate with C# scripts?
« Reply #2 on: August 04, 2020, 09:26:46 AM »
You can use Unity events and SendEvent(), however, I've newer used it that way.

I have a couple of scripts that send events directly to FSMs. I switched my core systems to scripts a while ago, and use PlayMaker more for the lower level stuff.

This is surprisingly simple to do. First, create a field to drag in an FSM directly (usually attached to the same game object).

Code: [Select]
public PlayMakerFSM attachedFSM;
and then, you can send an event like so:

Code: [Select]
attachedFSM.SendEvent("myEvent");
In my case, I use this for the health / damage system in a modified form.

Code: [Select]
public PlayMakerFSM[] FSMOnDamage;
public string damageEvent;

...

for (int i = 0; i < FSMOnDamage.Length; i++)
{
FSMOnDamage[i].SendEvent(damageEvent);
}

In this case, the event name is dynamic and set by the incoming damage type, e.g. "Fire". Also, you can see, I can attach any number of FSMs which each receive this event.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Best way to communicate with C# scripts?
« Reply #3 on: August 04, 2020, 10:09:40 AM »
Hi.
Indeed Get/Set Property and Call Method actions use of reflection (meaning slower than dedicated actions) and for most platforms you need to use the Linker Wizard as well.

So if you can avoid them its always better.

The Playmaker Api  can help to directly communicate with scripts.

Also this video can help making custom actions :


hyperhuzaifa

  • Playmaker Newbie
  • *
  • Posts: 9
Re: Best way to communicate with C# scripts?
« Reply #4 on: August 04, 2020, 05:35:38 PM »

The Playmaker Api  can help to directly communicate with scripts.


When you say Playmaker API - you mean custom action?
I was thinking of a system like this inside playmaker:
https://assetstore.unity.com/packages/tools/integration/event-system-dispatcher-12715

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Best way to communicate with C# scripts?
« Reply #5 on: August 04, 2020, 06:11:15 PM »
Hi.
The api has information how to communicate with other scripts and how to make custom actions.

The asset store package 'event system dispatcher' does not work out of the box neither.

If you have scripts that are not written to use with this asset you still need to edit those.