That’s not a bug, the Start function can be a coroutine.
I’d link you the documentation, but I can’t seem to find it (although I’m sure I’ve seen it before)
Also “yield return null” makes it yield until the next frame
I read it before posting, quote: “When using JavaScript it is not necessary to use StartCoroutine, the compiler will do this for you. When writing C# code you must call StartCoroutine.”
That page doesn’t actually say anything about the start function being a coroutine, but they do use it as one in one of the code examples.
Regardless, the start function can be used as a coroutine, that’s a fact,
But I don’t even use it in the actual game code, so it’s irrelevant to the actual problem at hand, namely the memory leak.
I’m pretty sure that (by omission) you don’t know or care what a “memory leak” is, and that you have seen some metric of memory use go up in some tool like Windows Task Manager…
I’m telling you where I see the issue is, I think the least you could do is humour me enough to try the one line change to confirm if it has any impact on your memory use issue.
Youre telling them where you THINK the issue is. Start being an IEnumerator and using yield return null there is perfectly valid and has no reason to cause a leak.
I havent tried it myself but I can assume this portion of code is not the issue.
A recent Unity version actually has a memory leak so it could be that. Are you on Unity 2017? (Donjt know the specific version)
Not really sure how the UI Text element works but I’m suspicious that changing its color might be the cause of the ‘leak’. It might not even but a leak but just a lot of garbage - although 10 MB/sec is a lot of garbage!
Generally speaking, uGUI is well known for its performance issues when dealing with constantly changing UI elements. At the very least, that color change is likely causing the UI to rebuild it’s mesh. It might even be creating a new material every frame! I’d suggest you try either a deep-profile, profiling in an actual build, or even just removing the change to the UI element and see what that does. In a pinch you could go download the uGUI source code and have a look to see if changing the color of the text has any large scale impacts.
Also, this UI element you are parenting to the rest of the gameobject. Are there many other UI elements on that same gameObject? If there are and they don’t change then that could be another issue as such a change to the canvas requires the entire canvas UI mesh to be completely rebuilt.
I’m sorry, I didn’t mean to be rude. I was just annoyed by the memory leak.
Maybe I should have mentioned that I used the profiler to look for the leak, that’s how I found it was the ui.text element that caused the mesh memory to go up.
And I actually did try what you suggested, as I don’t even use the start function as a coroutine in the actual game code, so I’m sure it’s not what causes the memory leak.
Yes, I am using the 2017 version, namely 2017.1.0f3
Do you happen to know if Unity fixed it in a more recent version?
I’ll update my Unity then
Yes, it is the color change that seems to cause it, as when I replace the line “color.a = progress;” with “color.a = 1;” there is no memory leak.
Also, I should mention that I added a couple of outline and shadow components to the text element, without it the memory leak is a lot smaller.
I did profile an actual build and it behaves the same.
In the actual game, I’m using this to display points the player gains
Maybe I should just not use the UI system for this then?
But then it will be more complicated to display numbers without the ui system. :s