Add the ability to get a list of points from a polyline

Avatar
  • updated
  • Completed

I'd just like to be able to do something like:

List<PolylinePoint> pointList = myPolyline.GetPointList();
Or
List<Vector3> pointList = myPolyline.GetPointList();
Reporting a bug? please specify Unity version:
Reporting a bug? please specify Shapes version:
Reporting a bug? please specify Render Pipeline:
Pinned replies
Avatar
Freya Holmér creator
  • Answer
  • Completed

this has now been added in a use-at-your-own-risk basis in the upcoming version!

Avatar
Freya Holmér creator
  • Answer
  • Completed

this has now been added in a use-at-your-own-risk basis in the upcoming version!

Avatar
Freya Holmér creator

oh, you can access the individual elements already if you want!
Iinstead of myPolyline.GetPointList()[index] you can do myPolyline[index], for both getting and setting points!

I could give access to the actual point list, but, then again, the user has to mark it as out of date manually if they ever modify that list

Avatar
John Close
Quote from Freya Holmér

I have been a little hesitant doing this, because modifying that list will not update the mesh unless you tell it to, which feels like hidden/weird behavior, so I was hoping I could only provide wrapper methods for doing it in ways that also update the mesh in the process

what is your use case for getting the point list that isn't covered by the existing methods?

In my game the player can draw a path, so I use the line to draw the player's path then move to each point on the line so I was planning to just do something like.

public PolylinePoint GetPointOnLine(int index){
    myPolyline.GetPointList()[index];
}

Makes sense why you'd do it this way, I guess I just kinda assumed at the time of writing that I could. The player can also modify the line during gameplay so being able to do something like this was kinda what I assumed I could do.

List<PolylinePoints> linePoints = myPolyline.GetPointList();
linePoints[selectedIndex].point = ctx.ReadValue<Vector2>(); //mouse position
myPolyline.SetPoints(linePoints);

Currently I just keep a copy of the points in a list next to the Polyline and then set the points when I add a new point on the line.

List<Vector2> linePoints = new List<Vector2>();
//... later
linePoints[selectedIndex].point = ctx.ReadValue<Vector2>(); //mouse position
myPolyline.SetPoints(linePoints);

My only other thought is it would be useful for copying the Polyline

Polyline secondLine = new Polyline();
secondLine.SetPoints(firstPolyline.GetPointList());

Anyway it's not critical I just guessed it'd be useful but I can understand the reasoning otherwise.

Avatar
Freya Holmér creator
  • Under Consideration

I have been a little hesitant doing this, because modifying that list will not update the mesh unless you tell it to, which feels like hidden/weird behavior, so I was hoping I could only provide wrapper methods for doing it in ways that also update the mesh in the process

what is your use case for getting the point list that isn't covered by the existing methods?