playMaker

Author Topic: Get an Object Component's Game Object  (Read 979 times)

westingtyler

  • Sr. Member
  • ****
  • Posts: 277
    • My Video Game Projects Web Site
Get an Object Component's Game Object
« 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?
« Last Edit: December 06, 2020, 05:01:06 PM by westingtyler »

justifun

  • 1.2 Beta
  • Sr. Member
  • *
  • Posts: 280
Re: Get an Object Component's Game Object
« Reply #1 on: June 07, 2022, 04:52:26 PM »
Did you ever find a solution to this?

Twood

  • Junior Playmaker
  • **
  • Posts: 76
Re: Get an Object Component's Game Object
« Reply #2 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.

ChrisFishFern

  • Playmaker Newbie
  • *
  • Posts: 5
Re: Get an Object Component's Game Object
« Reply #3 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!

wetcircuit

  • Full Member
  • ***
  • Posts: 158
    • wetcircuit.com
Re: Get an Object Component's Game Object
« Reply #4 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.