Playmaker Forum
PlayMaker Help & Tips => PlayMaker Help => Topic started 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:
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!
-
Hi,
uhm, good point, we need such action.
I fixed your action and put it on the Ecosystem basically, you had to do this:
Component _mb = componentToUse.Value as Component;
if (_mb != null) {
storeGameObject.Value = _mb.gameObject;
} else {
storeGameObject.Value = null;
}
Bye,
Jean
-
Awesome thanks again as always Jean!