Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: westingtyler on December 06, 2020, 04:59:17 PM

Title: Get an Object Component's Game Object
Post by: westingtyler on December 06, 2020, 04:59:17 PM
I couldn't find anything for this. I have 30 TMProUgui's in an array. I use a "array for each" to send a template fsm that processes each entry. in that template fsm I need to take the component and get the game object it is attached to. Some have said to use 'get owner' but that seems to just get the game object the FSM component is attached to. I don't need the game object the template is somehow attached to, I need the game object that has the TMProUgui component attached. The Get owner action has no option to select a an obj component to get the owner of. what am I missing?
Title: Re: Get an Object Component's Game Object
Post by: justifun on June 07, 2022, 04:52:26 PM
Did you ever find a solution to this?
Title: Re: Get an Object Component's Game Object
Post by: Twood on June 08, 2022, 01:53:37 PM
One possible way to do it in that situation is have a second array that stores the game object at some point, and keep the arrays in the same order. Then you just use the index number to track down the game object later.
Title: Re: Get an Object Component's Game Object
Post by: ChrisFishFern on June 11, 2022, 01:44:20 AM
Another way you could possibly approach it would be to create a custom action that uses the component reference to then get the GameObject it is attached to. The .gameObject property ([url].https://docs.unity3d.com/ScriptReference/Component-gameObject.html/url]) would be handy for this.

You could set up an FsmObject variable as an input for this custom action, and set it's type to the relevant component, which would then let you have a super handy interaction with PlayerMaker itself.

This could be way off the mark, as I'm a beginner, but this is the approach I've been taking when working on my own project and it has seemed to work really well, as PlayMaker's ability to work custom scripts into actions is super handy for specific stuff like this.

Best of luck!
Title: Re: Get an Object Component's Game Object
Post by: wetcircuit on June 11, 2022, 07:46:56 AM
Unity can get the transform of a component, as a shortcut to getting the gameobject:

https://docs.unity3d.com/ScriptReference/Component-transform.html

idk if there is a PM action.