x


Guidance needed to use Handles.DrawAAPolyLine in JS

Hi guys, I'm trying to use this function to draw a line on the screen:

Handles.DrawAAPolyLine

I pass in a Vector3[] array but i got a compile error:

BCE0017: The best overload for the method 'UnityEditor.Handles.DrawAAPolyLine(*UnityEngine.Vector3[])' is not compatible with the argument list '(UnityEngine.Vector3[])'.

what does this mean? Thanks .

more ▼

asked Jan 10 '11 at 10:15 AM

Eddie 2 gravatar image

Eddie 2
29 5 6 10

Could you please post a bit more information? I made a quick repro and I couldn't get this error. I'd like to see your call to DrawAAPolyLine and the definition of the object passed in.

Jan 10 '11 at 11:22 AM Statement ♦♦

Actually, what happens is that I get the error in JS but not in C#. It is probably due to the params type.

Jan 10 '11 at 11:23 AM Statement ♦♦
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

The error says that the function has a parameter type of *Vector3[] (pointer to vector3 array). You are passing in a Vector3[] (vector3 array - not a pointer to one). In C#, the signature reads as params Vector3[], which means that you can pass several Vector3s separated by comma, or send a vector3 array. I think this is a design bug in Unity.

It seems that the function expects a pointer to an array of Vector3. I am not well versed in JS to know how to obtain a pointer, or if it is even possible to obtain the pointer of an array. Until someone else post a definite answer how to solve this in JS I can present you a workaround with C# code, proxying the call without the params version. Your JS code can then call this instead of Handles.

Put this in Standard Assets folder to ensure it compiles before your script.

using UnityEngine;
using UnityEditor;

/// <summary>
/// Handles eXtension.
/// Provides support to DrawAAPolyLine functions for JS.
/// </summary>
public static class HandlesX
{
    public static void DrawAAPolyLine(Vector3[] points)
    {
        Handles.DrawAAPolyLine(points);
    }
    public static void DrawAAPolyLine(float width, Vector3[] points)
    {
        Handles.DrawAAPolyLine(width, points);
    }
    public static void DrawAAPolyLine(Texture2D lineTex, Vector3[] points)
    {
        Handles.DrawAAPolyLine(lineTex, points);
    }
    public static void DrawAAPolyLine(Texture2D lineTex, float width, Vector3[] points)
    {
        Handles.DrawAAPolyLine(lineTex, width, points);
    }
}

Then you can use HandlesX.DrawAAPolyLine in a similar fashion, from your JS code.

more ▼

answered Jan 10 '11 at 11:39 AM

Statement gravatar image

Statement ♦♦
20.1k 35 70 175

(comments are locked)
10|3000 characters needed characters left

The error is gone after I passed in the elements of the vector3 array instead of the whole array:

Handles.DrawAAPolyLine(vecArray[0], vecArray[1], vecArray[2]);

I get the error if I pass in vecArray:

Handles.DrawAAPolyLine(vecArray);

this is the function declaration:

static function DrawAAPolyLine (params points : Vector3[]) : void 
more ▼

answered Jan 12 '11 at 06:53 AM

Eddie 2 gravatar image

Eddie 2
29 5 6 10

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x580
x38
x18
x2
x1

asked: Jan 10 '11 at 10:15 AM

Seen: 893 times

Last Updated: Jan 10 '11 at 12:14 PM