Playmaker Forum

PlayMaker News => General Discussion => Topic started by: zahidur59 on December 13, 2017, 01:37:50 AM

Title: How to call a method of a attached component? [SOLVED]
Post by: zahidur59 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?
Title: Re: How to call a method of a attached component?
Post by: Fat Pug Studio 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.
Title: Re: How to call a method of a attached component?
Post by: zahidur59 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?
Title: Re: How to call a method of a attached component?
Post by: Fat Pug Studio on December 13, 2017, 10:06:05 AM
Hmm, i'll try it out.
Title: Re: How to call a method of a attached component?
Post by: zahidur59 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.
Title: Re: How to call a method of a attached component?
Post by: Fat Pug Studio on December 14, 2017, 04:10:56 AM
Hm, strange, this is what i get when i try to invoke the method on LineRenderer

(https://s26.postimg.org/8nt34uweh/screenshot_115.png)
Title: Re: How to call a method of a attached component?
Post by: zahidur59 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!
Title: Re: How to call a method of a attached component?
Post by: Fat Pug Studio 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? ???
Title: Re: How to call a method of a attached component?
Post by: zahidur59 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?
Title: Re: How to call a method of a attached component?
Post by: Fat Pug Studio on December 14, 2017, 02:30:47 PM
You can call any method, that's what they're for.
Title: Re: How to call a method of a attached component?
Post by: zahidur59 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?
Title: Re: How to call a method of a attached component?
Post by: Fat Pug Studio on December 14, 2017, 03:26:23 PM
Sure, in the morning, i'm afk for today.
Title: Re: How to call a method of a attached component?
Post by: zahidur59 on December 14, 2017, 03:41:45 PM
Thanks.
Title: Re: How to call a method of a attached component?
Post by: Fat Pug Studio 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:

(https://s26.postimg.org/pyfd2ifm1/screenshot_118.png)

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

(https://s26.postimg.org/6um1m62rt/screenshot_119.png)

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

(https://s26.postimg.org/hipsl0cqx/screenshot_120.png)

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.

(https://s26.postimg.org/uhrlo0xhl/screenshot_117.png)

Sorry, invoking method was not the right solution since it needs arguments, so use call method.
Title: Re: How to call a method of a attached component?
Post by: zahidur59 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.
Title: Re: How to call a method of a attached component?
Post by: Fat Pug Studio on December 15, 2017, 04:09:51 AM
You're welcome ;)