playMaker

Author Topic: How to call a method of a attached component? [SOLVED]  (Read 5856 times)

zahidur59

  • Playmaker Newbie
  • *
  • Posts: 8
How to call a method of a attached component? [SOLVED]
« on: December 13, 2017, 01:37:50 AM »
Hi, I'm a Noob to PlayMaker so I just can't figure how to call a method of component attached to an Owner. I have a lineRenderer stored in FSM variable and want to call it's SetPosition method. Just can't figure out how to do that. 

I've searched the forum but failed to find anything related. Anyone care to help me out on this?
« Last Edit: December 15, 2017, 09:48:20 AM by djaydino »

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Re: How to call a method of a attached component?
« Reply #1 on: December 13, 2017, 02:11:30 AM »
There are two ways you can accomplish this. First is to create a new variable of object type and select the parameter you want to manipulate. Second is using Invoke Method, select the object that holds the component and type in the method name.
Available for Playmaker work

zahidur59

  • Playmaker Newbie
  • *
  • Posts: 8
Re: How to call a method of a attached component?
« Reply #2 on: December 13, 2017, 03:01:36 AM »
Thanks for answering krmko but none of these method actually working for me. As you see I have the linerenderer saved as a variable called Laser and when I try to set the parameter of Laser, there are no access to the method setPosition or the positions are offered as variables.

For the second method, I can't select or point to the component as Its not listing it.

Am I missing something?

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Re: How to call a method of a attached component?
« Reply #3 on: December 13, 2017, 10:06:05 AM »
Hmm, i'll try it out.
Available for Playmaker work

zahidur59

  • Playmaker Newbie
  • *
  • Posts: 8
Re: How to call a method of a attached component?
« Reply #4 on: December 14, 2017, 03:07:57 AM »
Got a custom script to do the job but still needs to know how to invoke a predefined method of a component of gameObject. I know we can call the methods of customs scripts/behavior but don't how to do that for the standard components.

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Re: How to call a method of a attached component?
« Reply #5 on: December 14, 2017, 04:10:56 AM »
Hm, strange, this is what i get when i try to invoke the method on LineRenderer

Available for Playmaker work

zahidur59

  • Playmaker Newbie
  • *
  • Posts: 8
Re: How to call a method of a attached component?
« Reply #6 on: December 14, 2017, 07:10:09 AM »
Can you please state how you called the method? I can't even figure out how to call a method of an standard component!

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Re: How to call a method of a attached component?
« Reply #7 on: December 14, 2017, 01:21:59 PM »
Use Unity API documentation for that stuff, it's UnityEngine.LineRenderer, tho you can type only LineRenderer. The cast exception is quite strange, any ideas? ???
Available for Playmaker work

zahidur59

  • Playmaker Newbie
  • *
  • Posts: 8
Re: How to call a method of a attached component?
« Reply #8 on: December 14, 2017, 01:47:00 PM »
No idea. I'm new to both Unity and playmaker. So you can call other method of linerenderer? Like SetPosition from playmaker?

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Re: How to call a method of a attached component?
« Reply #9 on: December 14, 2017, 02:30:47 PM »
You can call any method, that's what they're for.
Available for Playmaker work

zahidur59

  • Playmaker Newbie
  • *
  • Posts: 8
Re: How to call a method of a attached component?
« Reply #10 on: December 14, 2017, 02:52:38 PM »
I can't seems to figure out how to do that. Can you please give me a step by step list if not too much trouble?

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Re: How to call a method of a attached component?
« Reply #11 on: December 14, 2017, 03:26:23 PM »
Sure, in the morning, i'm afk for today.
Available for Playmaker work

zahidur59

  • Playmaker Newbie
  • *
  • Posts: 8
Re: How to call a method of a attached component?
« Reply #12 on: December 14, 2017, 03:41:45 PM »
Thanks.

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Re: How to call a method of a attached component?
« Reply #13 on: December 15, 2017, 02:36:46 AM »
Here it is in a nutshell. First, the link to the unity scripting API:

https://docs.unity3d.com/ScriptReference/LineRenderer.SetPosition.html

or, you can click the small book with "?" in the component in inspector which will open unity documentation on LineRenderer. Here is what it looks like:



By clicking Switch to Scripting, you switch to scripting API with properties, methods etc.



You will find the SetPosition method there, and by clicking on it you will see the following:



LineRenderer is the name of the class, so you enter that in the class name (or UnityEngine.LineRenderer, whichever you prefer). Method is SetPosition, and below you can enter the parameters, in your case int (which position to set) and vector3 (new position to set). In the end, it should look like this.



Sorry, invoking method was not the right solution since it needs arguments, so use call method.
Available for Playmaker work

zahidur59

  • Playmaker Newbie
  • *
  • Posts: 8
Re: How to call a method of a attached component?
« Reply #14 on: December 15, 2017, 04:04:28 AM »
This is exactly what I was looking for. Thanks man. I really appreciate the effort you put into this.