0

am a beginner at unity and c# as well. i followed a tutorial in youtube, and i did every thing as he did but i got an error. am trying to animate a drawn graph. the error in console is as follows: error CS1061: 'List<Vector2>' does not contain a definition for 'Clone' and no accessible extension method 'Clone' accepting a first argument of type 'List<Vector2>' could be found (are you missing a using directive or an assembly reference?)

and the part in script that has the problem is this one:

void AnimateLine(UILineRenderer line){
    List<Vector2> points = line.points.Clone();
    Animate(line, points);
}

i don't know how to define Clone() in List<Vector2>, am a beginner so excuse my ignorence.

for now I tried nothing and this was my first place to ask that.

General Grievance
  • 4,555
  • 31
  • 31
  • 45
  • I can't reproduce the problem in the question because `UILineRenderer` isn't defined here for me. Question needs to include a definition or at least some documentation for this mysterious `UILineRenderer` type. – Ruzihm Mar 31 '22 at 19:27
  • UILineRenderer is a script responsible of drawing the graph lines. – user18647367 Mar 31 '22 at 19:31
  • Do i need to share the files. – user18647367 Mar 31 '22 at 19:32
  • You could try `List points = new List(line.points);` – Ruzihm Mar 31 '22 at 19:34
  • thank you @Ruzihm i tried it but i don't know what was Clone() function means in the original script. – user18647367 Mar 31 '22 at 19:36
  • It works The editor doesn't give me errors any more . but are you sure the line "List points = new List(line.points); " do the same work as the line "List points = line.points.Clone();" – user18647367 Mar 31 '22 at 19:40
  • 2
    No. I don't know what the author of the tutorial you are following defined as `List.Clone()` but it is not standard, so I can only guess. Does this answer your question? [How do I clone a generic list in C#?](https://stackoverflow.com/questions/222598/how-do-i-clone-a-generic-list-in-c) – Ruzihm Mar 31 '22 at 19:44
  • thanks again @Ruzihm, it didn't work as expected. this is the video url "https://www.youtube.com/watch?v=--LB7URk60A" go to minute 7:58 am trying to create the same script as he did, thanks again and am sorry for the burden. – user18647367 Mar 31 '22 at 19:51
  • What did not work as expected? What happened instead? What was expected to happen? Please be more descriptive then include enough code to reproduce the "what happened instead" outcome. There needs to be enough info for someone to know if the problem is due to the code I've given you here or any of the other code running on your device (which may be different from the code in the video due to personal choices, typos, etc). See [mre] for more info. – Ruzihm Mar 31 '22 at 20:04
  • am sorry. as i said at the beginning am a beginner, did you saw the video i linked. – user18647367 Mar 31 '22 at 20:07
  • how can i link script files. – user18647367 Mar 31 '22 at 20:09
  • [edit](https://stackoverflow.com/posts/71697996/edit) the question and include your scripts in the body there. You can format your code in a few ways. [This way](https://meta.stackoverflow.com/a/306845/1092820) is probably the easiest. – Ruzihm Mar 31 '22 at 20:12
  • here is the files i uploaded them to my google drive."https://drive.google.com/drive/folders/1H_B-sfyLdhW5okQu7_34eT7Gjn54jHXE?usp=sharing" – user18647367 Mar 31 '22 at 20:14
  • they must be in the same place for the declaration to work properly right. – user18647367 Mar 31 '22 at 20:15
  • The quality of the question will be greatly reduced if that link is ever removed or breaks so please include relevant parts of the code in the body of the question itself. – Ruzihm Mar 31 '22 at 20:17
  • For now I took a look at this code and it still has an undefined call to `Clone`. I would instead use `void AnimateLine(UILineRenderer line) { List points = new List(line.points); Animate(line, points); }` – Ruzihm Mar 31 '22 at 20:21
  • i did tried it the error is gone. but when i tried to call the function AnimateLines() frome the script to the refresh button as the video shows, nothing happened. as i think the purpose of that animatorScript is to animate the lines usnig LeanTween tool but i just can't understand how. – user18647367 Mar 31 '22 at 20:33
  • when i tried your answer the script gives me a field called "Lines" in the inspector i will attach the screen shot now. – user18647367 Mar 31 '22 at 20:36
  • this is the link : "https://drive.google.com/drive/folders/1gob5S327XTY8q3h_ngYlq7J3md6oVXL8?usp=sharing" – user18647367 Mar 31 '22 at 20:37
  • i think you need to take a look at the three scripts cause i think that those scripts uses components from each other. – user18647367 Mar 31 '22 at 20:41
  • You need to add your `UILineRenderer` instances to the `GraphAnimator.lines` array before you call `AnimateLines`. From your screenshot I can now tell that you have not done that. You could do this in code or in the inspector if your lines exist at edit time. IF you're doing it in code, that array should probably be a `List` instead, so that the size can change and lines can be added to it more easily. – Ruzihm Mar 31 '22 at 21:27
  • @Ruzihm thank you again for your time. i just tried it it gives me "Assets\Scripts\GraphAnimator.cs(28,38): error CS0029: Cannot implicitly convert type 'System.Collections.Generic.List' to 'System.Collections.Generic.List'" – user18647367 Mar 31 '22 at 21:41
  • `List points` was fine. that's not an array, that's a list, so it was not what i was talking about. The array I was talking about is the `GraphAnimator.lines` array. Anyway, this is [becoming about a completely different topic.](https://meta.stackexchange.com/q/43478/405359) Consider asking a new question and including the necessary information there. – Ruzihm Mar 31 '22 at 21:44
  • could you explain to me please how to do that. – user18647367 Mar 31 '22 at 21:45
  • the line are existed like in this img : "https://drive.google.com/drive/folders/1BEN7U3wNCnbDWlkWliYgHEXQMtFQit-f?usp=sharing" there is a game object called "Grid" under it there is the script 'UILineRenderer' attached to an empty game object called "Image", and from there i draw points. the only role of the GraphAnimator.cs script is to animate the line as in the video. – user18647367 Mar 31 '22 at 21:49
  • Again am so sorry for the burden and excuse my unprofessionalism in using StackOverflow platform. am sorry again. – user18647367 Mar 31 '22 at 21:54

0 Answers0