playMaker

Author Topic: Get Component's Owner?[SOLVED]  (Read 1942 times)

serenefox

  • Full Member
  • ***
  • Posts: 135
    • Serenefox Games
Get Component's Owner?[SOLVED]
« on: August 21, 2018, 07:22:44 PM »
Hello Playmaker Community,

I am wondering if there is a way to get a gameObject value from a component's value.

Here is my situation:

I am using get property to grab a property of a third party script. The value I am grabbing returns a "object" value. How can I get the gameObject that the value is associated with? The objects value is a component on a gameObject created at runtime. Does that make sense to anybody? haha

I have a custom action started but it wont save the object value:

Code: [Select]
using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{

[ActionCategory(ActionCategory.UnityObject)]
[Tooltip("Gets the owner gameobject of a component")]
public class GetComponentOwner : FsmStateAction
{
        [RequiredField]
        public FsmObject componentToUse;

        [UIHint(UIHint.Variable)]
        public FsmGameObject storeGameObject;

        public override void Reset()
        {
            componentToUse = null;
            storeGameObject = null;
        }

        // Code that runs on entering the state.
        public override void OnEnter()
{
            DoGetComponentOwner();

            Finish();
}

        public void DoGetComponentOwner()
        {
            storeGameObject.Value = componentToUse.Value as GameObject;
        }


}

}


Thanks for any suggestions!
« Last Edit: September 12, 2018, 01:08:03 AM by jeanfabre »
Most Recent Published Games:
Juicy Theater - Android

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Get Component's Owner?
« Reply #1 on: August 29, 2018, 02:56:22 AM »
Hi,

 uhm, good point,  we need such action.

 I fixed your action and put it on the Ecosystem basically, you had to do this:

Code: [Select]
Component _mb = componentToUse.Value as Component;
if (_mb != null) {
storeGameObject.Value = _mb.gameObject;
} else {
storeGameObject.Value = null;
}

 Bye,

 Jean

serenefox

  • Full Member
  • ***
  • Posts: 135
    • Serenefox Games
Re: Get Component's Owner?
« Reply #2 on: September 12, 2018, 01:07:19 AM »
Awesome thanks again as always Jean!
Most Recent Published Games:
Juicy Theater - Android