Author Topic: Get Component  (Read 4798 times)

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3905
  • Official Playmaker Support
    • View Profile
    • LinkedIn
Get Component
« on: December 09, 2011, 07:23:32 PM »
Gets a Component on a GameObject at runtime and stores it in an Object variable.

NOTE: Set the Object variable's Object Type to get a component of that type. E.g., set Object Type to UnityEngine.AudioListener to get the AudioListener component on the camera.

HINT: Combine this action with Get Property and Set Property actions to manipulate components on GameObjects.


  • Full Member
  • ***
  • Posts: 134
    • View Profile
    • my twitter @andrewlukasik
Re: Get Component
« Reply #1 on: December 11, 2011, 05:58:31 PM »
Thank you Alex! I needed that :)


  • Guest
Re: Get Component
« Reply #2 on: January 02, 2012, 08:12:58 PM »
aah, close but no cigar yet  ???

If I attach a script to a game object (say XYZ) and then create an object variable (abc) which I then set to that type using the "edit variable" inspector in the playmaker state editor window, I can then use Set or GetProperty to access a runtime object with a component of that type. The problem is that when authoring that state the Get/SetProperty action lets me set the target object to ABC. The Property selector appears and shows the instance variables for the object. But there's no source or destination for the data. If I use one of the "inherited" variables like gameObject, or transform, the src/destination field appears but doesn't in this case.

If you use Get/SetProperty on GO that's in the Heirarchy, a little dropdown would appear letting you set the dest or source for the access (an int, float, etc). In this case it doesn't show up.

I hope it's just  me misunderstanding this somehow.

Well I thought of something else: I added get{} set{} and it worked. Should have thought of that right off. Sending this along anyway in case someone else gets confused.