Texture tilling problem on iOS
Hi ! I'm currently coding a game with my team, and we have a strange problem.
At some point, we need to draw a line from point A to point B gradually. I works great on every devices we own, except from the iPhone 5 (iOS 10.2.1) and the Ipad (1st gen, 9.3.5) (works on iPhone 6).
The problem is that on this devices, the line starts to "draw", but after the first "update", it stops, leaving the line incomplete (no error, and the game works well). At first, we used a DIY solution based on "while" and calculations, so we tried using Lerp, same issue.
That's really strange... As someone ever encounter this problem?
EDIT : added code for the drawing
GameObject line_tmp = Instantiate(line_fig_prefab);
line_tmp.GetComponent<LineRenderer> ().SetPosition (0, pos_line_end);
line_tmp.GetComponent<LineRenderer> ().SetPosition (1, pos_line_end);
float t = 0f;
while (line_tmp.GetComponent<LineRenderer> ().GetPosition (1) != end_pos)
{
line_tmp.GetComponent<LineRenderer> ().SetPosition (1, Vector3.Lerp(pos_line_end, end_pos, t));
t += 0.05f;
yield return null;
}
EDIT 2 : Finaly found why. On old Apple devices (iPhone 5, iPad 1, ...), the texture needs to be POT sized (16x16, 32x32, ...). Thanks Harinezumi for your help !
Could you please provide more information about which version of Unity you are using and how do you draw the lines? (off the top of my head I can list 3 very different ways).
Either way, this will probably be a graphics capability issue.
This should be working, just at 1/2-speed. $$anonymous$$aybe try also placing a small ball at endPos? $$anonymous$$y guess is it's an issue with the lineRenderer not displaying correctly, and you will see the ball move.
Harenizumi suggests changing the curPos!=endPos to t<1. That's not a bad idea, but it's not the problem. Even if the loop runs forever, it should still move the line (also there's no float rounding problem with Lerps -- when t>=1 it gives the exact end as the result.)
Likewise H's suggestion of using deltaTime*3 ins$$anonymous$$d of 0.05 might be better (but still not the same as 60fps,) but your code should still be moving the line, just slower.
Answer by Harinezumi · Oct 20, 2017 at 11:27 AM
Is your texture POT sized? I've found some answers that were solved by changing the texture to a power of two size, e.g. here. Another possible issue could be the limited precision of UVs on iOS - described here.
Exactly what I found when I wrote the last comment :) I'm trying it right now
That was it ! Seems like old Apple devices need to have POT sized textures to tile it :)
Perfect, glad that it is now solved! :)
Answer by Harinezumi · Oct 18, 2017 at 12:50 PM
Thanks for providing code example.
I would make some changes to the code (see below). However, I'm not sure this will solve your issues with certain hardware. If not, just comment on it and I'll try to help figuring it out.
public LineRenderer line_fig_prefab;
private IEnumerator DrawLineCoroutine () {
LineRenderer line_tmp = Instantiate(line_fig_prefab); // this way you immediately get the LineRenderer component
line_tmp.SetPosition (0, pos_line_end);
line_tmp.SetPosition (1, pos_line_end);
float t = 0f;
// while (line_tmp.GetPosition (1) != end_pos) due to floating point imprecision this will always be true; instead use
while (t < 1) // or even better: t < lineDrawDuration
{
line_tmp.SetPosition (1, Vector3.Lerp(pos_line_end, end_pos, t)); // if using lineDrawDuration use here t / lineDrawDuration
t += Time.deltaTime; // will draw using real update time
yield return null;
}
line_tmp.SetPosition(1, end_pos); // making sure that the end point is set precisely, even if t overshoots
}
Sorry for any syntax errors and missing formatting, I'm writing from my phone.
Can't try this right now, because the person who has the iPhone and iPad left an hour ago, but be sure I'll try this tomorrow !
The problem is still here with this method :/
$$anonymous$$aybe it is the same issue as here?