Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: serenefox on August 21, 2018, 07:22:44 PM

Title: Get Component's Owner?[SOLVED]
Post by: serenefox 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!
Title: Re: Get Component's Owner?
Post by: jeanfabre 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
Title: Re: Get Component's Owner?
Post by: serenefox on September 12, 2018, 01:07:19 AM
Awesome thanks again as always Jean!