- Home /
The question is answered, right answer was accepted
[Solved] How to correctly use TrailRenderer.GetPositions
Good day.
I tried various combinations and i cant find the correct way to write it.. I need to extract all the points of a trail that has been rendered. To store them and use it in other things.
I'm trying this, but its not correct:
Vector3[] TrailRecorded = GetComponent<TrailRenderer>().GetPositions();
But as i see, the GetPositions return an integrer.. so im little confused. some help?
Thanks and Bye!
Answer by bourriquet · Apr 08, 2018 at 09:06 AM
This functions fills an array that you give as parameter, and returns the number of elements that were put in it. This is a more optimized way than returning an array, because it doesn't require allocating new memory space.
Here is how you should use it:
const int MAX_POSITIONS = 100;
Vector3[] TrailRecorded = new Vector3[MAX_POSITIONS];
void YourFunction ()
{
int numberOfPositions = GetComponent<TrailRenderer>().GetPositions (TrailRecorded);
}
Then you can use the numberOfPositions first elements in TrailRecorded as needed. The other elements are either empty or out-of-date.
Good day. Ahh okk! i was misunderstanding the function. You can also do direct
TrailGenerator.GetPositions(TrailRecorded);
Thaanks!