Dissapearing timer?

After coding my timer, I went to test play in Unity and the timer all together disappears on play. There are 0 errors reported in my code. I keep reviewing the videos and lecture codes to see where the issue is without any luck, I’m sure I could fix it if I could just locate it. Any ideas on where or what might be causing this issue? (4:25 time stamp of video 61)



Hi Rexx,

Thanks for sharing your screenshots. Unfortunately, I’m not able to see the problem. The timer visualisation is visible in the top right corner of the game window in all screenshots and in the Hierarchy of all screenshots.

What did you expect to see?

I was expecting to see the timer sprite remain in place and slowly start to disappear counterclockwise.
However upon play the sprite goes missing, while the fill fraction in the Inspector does count showing that the code is working.

Could there be a second Timer component in the scene which affects the sprite?

The fill amount refers to the percentage of the filling, so it must range between 0 and 1. In your first and second screenshot, you have got negative values. Actually, you want to start at 1 (= 100%). Try to set the initial value to 1 and test your game again.

I did, and the timer still disappeared. I restarted the project.

Have you already tried to add Debug.Logs to your code to see what is going on during runtime? Log all relevant values into your console. Maybe the fill amount value is not ranging between 0 and 1 while the game is running.

Another student had a similar problem as you. He accidentally assigned the sprite from the assets folder to the Image component instead of the sprite from the hierarchy.

Hello, I had the exact same problem and I found a solution which worked for me.
The real reason the timer would disappear was because I never called UpdateTimer() within the Update method of Timer.cs. This means the timer value was initialized at 0 and never changed, resulting in a 0% fill or invisible timer.

In terms of how you could find this yourself, what lead me to this realization was using Debug.Log("Setting timer fill amount to " + timer.fillFraction); within the Update method of Quiz.cs. This printed “Setting timer fill amount to 0” on every frame.

As a very small suggestion to the instructor, please don’t rush through these important steps. I understand that it was paced perfectly fine for somebody watching the screen intently, but in reality I tend to code along while the video is playing quite frequently. So if, for example, the TimerImage component is being added from the hierarchy and not the asset folder, it would be useful to explicitly state this aloud as well as performing the action on screen, especially considering the on screen time is a few seconds maximum and very easy to be looking away. Realistically this comes down to my own fault of not watching intently but I imagine there are many more students like me out there :stuck_out_tongue:

1 Like

Privacy & Terms