playMaker

Author Topic: How to refer "This" MonoBehaviour GameObject in Playmaker Action  (Read 1318 times)

Christoph

  • Beta Group
  • Sr. Member
  • *
  • Posts: 256
I know I had this before already, but I'm stuck again and can't find out how to solve it.

But I have this SDK I need to implement (Appsflyer) and am writing my own actions to trigger specific events at given times.

I have a particular problem with this code as seen in the attached screenshot:

Code: [Select]
AppsFlyeriOS.validateAndSendInAppPurchase("productIdentifier", "price", "currency", "tranactionId", null, this);
The problem lies in "this" which refers to a MonoBehaviour gameObject and the error is:
cannot convert from 'HutongGames.PlayMaker.Actions.AFIAPValidation' to 'UnityEngine.MonoBehaviour'

How can I resolve this (pun intended)?

Edit: can't attach any image because the upload folder is full.

but the method is:
Code: [Select]
void AppsFlyeriOS.validateAndSendInAppPurchase(string productIdentifier, string price, string currency, string tranactionId, Dictionary<string, string> additionalParameters, MonoBehaviour gameObject)

Christoph

  • Beta Group
  • Sr. Member
  • *
  • Posts: 256
Re: How to refer "This" MonoBehaviour GameObject in Playmaker Action
« Reply #1 on: July 09, 2022, 11:53:36 AM »
oh so I kinda remembered and I think all I have to do is to connect it to a script component that is based on MonoBehaviour. So I'm setting a gameobject variable and a monobehaviour variable, then get the script component on that gambeobject and store it into the monobehaviour variable and call that instead of "this".  :D

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7618
    • jinxtergames
Re: How to refer "This" MonoBehaviour GameObject in Playmaker Action
« Reply #2 on: July 09, 2022, 07:06:30 PM »
Hi.
You can use a FsmGameObject or FsmOwnerDefault.

IF you use FsmOwnerDefault, then you need to use this line :

Code: [Select]
var go = Fsm.GetOwnerDefaultTarget(gameObject);and use go

else use gameObject.Value

Christoph

  • Beta Group
  • Sr. Member
  • *
  • Posts: 256
Re: How to refer "This" MonoBehaviour GameObject in Playmaker Action
« Reply #3 on: July 11, 2022, 12:20:36 PM »
So what I did is this:

Code: [Select]
[RequiredField]
[Tooltip("The Game Object the Appsflyer script is attached to")]
public FsmOwnerDefault GameObject;
private MonoBehaviour _monoBehaviourClass;

public override void OnEnter()
{
_monoBehaviourClass = Fsm.GetOwnerDefaultTarget(GameObject).GetComponent<AppsFlyerObjectScript>();

#if UNITY_IOS
//for iOS
AppsFlyeriOS.validateAndSendInAppPurchase("productIdentifier", "price", "currency", "tranactionId", null, _monoBehaviourClass);

#elif UNITY_ANDROID
//for Android
            //AppsFlyerAndroid.validateAndSendInAppPurchase( "publicKey",  "signature",  "purchaseData",  "price",  "currency",  null,  _monoBehaviourClass);
#endif

Finish();
}

I'm in the understanding I have to get a c# script based on monobehaviour. What does

Code: [Select]
var go = Fsm.GetOwnerDefaultTarget(gameObject);
do?