|
Post by mikeyj21 on Nov 26, 2021 14:28:47 GMT
Hi,
I have been using your wonderful camera system for ages, but have come across a bug that has started occurring.
Unfortunately the error occurs only about 1 time in 20 when repeating the same action.
I get a Nan error on line 740 in the ProCamera2D.cs, which is this line: _transform.localPosition = VectorHVD(Vector3H(newPos), Vector3V(newPos), Vector3D(_transform.localPosition));
This error spams the log, and causes a black screen in builds.
FYI, it seemed to start occurring after I added new code, setting timescale to 1 after previously setting it to 0 to show a tutorial video.
However, it seemed pretty easy to fix, so I thought I would post it here to help anyone else who might run into this!
Change line 740 to this:
//_transform.localPosition = VectorHVD(Vector3H(newPos), Vector3V(newPos), Vector3D(_transform.localPosition)); // the line above can fail with a Nan error (for me, its the call to Vector3H). // changed to check for the NaN error causing the problem; the game seems to be ok with just missing out the change of position! var a = Vector3H(newPos); var b = Vector3V(newPos); var c = Vector3D(_transform.localPosition); if (float.IsNaN(a) || float.IsNaN(b) || float.IsNaN(c)) print("-----> NaN ERROR: " + a + ", " + b + ", " + c); else _transform.localPosition = VectorHVD(a, b, c);
As you can see, all it does is ignore the error, and it stops erroring itself the moment the player moves enough to trigger a camera move.
Hopefully this helps someone!
Cheers, and thank you for making such a great component... It really is the only third-party add on that I literally add to every unity projct I make!
--Mike--
|
|
|
Post by Luís Pedro Fonseca on Nov 26, 2021 22:29:14 GMT
Thanks for the kind words mikeyj21 and for reporting this bug and potential fix. I'll try to pinpoint the issue and solve it. The timescale does give me some indication of what it might be.
|
|
|
Post by mikeyj21 on Dec 15, 2021 14:14:08 GMT
Darn it!
As soon as I submitted a build to my testing dept. (ok, I admit it.... my testing dept. is just a single guy who put's up with me harrassing him to try stuff!), it failed.
My lovely fix (Well, I thought it was lovely) didn't work.... he was able to move the player off the screen without the camera following him.
Wierd, though, because it seemed to work for me, but whether this was just because by coincidence I am not sure.
--Mike--
|
|
|
Post by Luís Pedro Fonseca on Dec 15, 2021 14:41:23 GMT
Hey Mike,
Can you send me a small project that reproduces this issue consistently either in-editor or in-device?
Cheers!
|
|
|
Post by mikeyj21 on Dec 15, 2021 15:19:26 GMT
Hi,
I will have a go at reproducing it in a sample project (although it does not happen consistantly anyway, maybe 1 time in 5?), but in the meantime:
I am pretty sure it is to do with setting the Timescale back to 1. I removed the code which sets the timescale to 0, and (after 50 repetitions of the action that causes the problem) it hadn't reoccurred. Of course, this is not something I can get away with really... I could avoid setting the Timescale to 0 when showing tutorial videos, but obviously the same problem could potentially occur after showing a menu screen.
Also, now I come to think of it, this could also be the cause of another problem that has been reported to me, but I wasn't able to reproduce; When my player sprite uses a teleport I also set the timescale to 0 until they fully 'materialise' in the new location. I was alerted that on one occasion the player sprite appeared in an unexpected location.... (i.e. the camera didn't follow it)
I have also tried setting the timescale back to 1 (after the player has finished watching the tutorial video) in a coroutine as below:
IEnumerator SetTimeScaleToOne() { yield return new WaitForEndOfFrame(); yield return new WaitForEndOfFrame(); //done twice to to be sure Time.timeScale = 1; }
..but that didn't solve the problem.
As I say I will try to duplicate it in a sample project, but being that my code is well into the second year of development (and thus is pretty big!), I am not sure how easy it will be to recreate the issue in a new project!
--Mike--
|
|
|
Post by mikeyj21 on Dec 16, 2021 19:26:28 GMT
Hi again Luis,
Ok, I have managed to strip my game down to a very basic project, and the error still occurs.
A few bits of information:
In the root directory, there is a short video showing the error occuring (this is called Demo.mp4). Luckily, the error occurred at the second attempt when recording!
Note that because I have removed the Library folder to reduce the filesize, Unity may open with a default blank scene (and also it takes a couple of minutes for the project to open the first time). The path to the correct scene is Assets/_MyContent/Scenes/Jungle_BootRoom.
The way to reproduce the error is as follows:
1) The very first action you perform after pressing Play must be to press the X button on your gamepad (this is on a XBox pad; i.e. the 'west' button of the 4 face buttons).
As soon as you do this a demo video will play. As you can see from the code, the Timescale is set to 0 when it starts playing.
2) Hold the Left Thumbstick to move 'east' (i.e, towards the right) and press the A ('south') button before the video finishes. This will cancel the video playback and set the Timescale to 1, and start the player moving.
If you are lucky, this will cause the error to occur.
If not, press the Y ('north') button to reload the scene. and repeat. You will know when it happens because the error log gets spammed with NaN errors. When I was double checking the process above though, it took me about 20 goes to get it to error!
Being that I have removed 99% of my code, and it still errors, I am pretty sure the error is due to moving the player at the instant the timescale reverts to 1.
I have my fingers crossed you can work your magic!
Many thanks for your support!
--Mike--
|
|
|
Post by Luís Pedro Fonseca on Dec 17, 2021 9:52:04 GMT
Thanks Mike! I'll try to look into this ASAP. Cheers!
|
|
|
Post by Luís Pedro Fonseca on Dec 18, 2021 18:45:14 GMT
Hi Mike, I was looking into this but I don't have a controller easily accessible to try this out. Also since I'm testing in editor it's a lot easier to control it by keyboard. I tried to update the project but it's a bit confusing. Can you please send me a version with support for keyboard controls? Thanks!
|
|
|
Post by mikeyj21 on Dec 19, 2021 19:39:08 GMT
Hi Luis,
Ok, I have uploaded a new version with keyboard control. Instructions as to what keys to use are provided on screen when you run the Jungle_BootRoom scene:
Many thanks!
--Mike--
|
|
|
Post by mikeyj21 on Jan 3, 2022 11:45:27 GMT
Hi again,
I hope you had a wonderful Christmas (if you celebrate it, of course) and New Year!
I didn't do any work on my game over the festive period, but I did have an idea, which I just implemented today (on my first day 'back' coding).
My idea failed miserably
...but thought I would share it with you just in case it helps narrow down the problem!
I changed the code so that, when the timescale changed from 0 to 1, a coroutine starts which disables input for 60 frames. I thought this might gives the camera a chance to catch up. However, the error still occurs.
I can only conclude it occurs when the camera moves, regardless of the time elapsed since changing timescale...
Cheers,
--Mike--
|
|
|
Post by Luís Pedro Fonseca on Jan 3, 2022 11:49:20 GMT
Hey Mike,
Thanks for the update. That does help me know that it's not that transition that causes it.
I wish we could reproduce this consistently. :/
|
|
|
Post by mikeyj21 on Jan 4, 2022 10:46:16 GMT
Hi,
Yes, my life seems to be full of bugs which are not consistantly reproducable at the moment.
...anyway, in an effort to help, I have made a small change to the code, which I have uploaded here:
I speculated that the inconsistant nature of the bug could be down to Unity's input scanning not occurring at the exact same time each attempt, so i made the player move automatically. Now, all you need to do is press the P key to start the video; when you press P again, the player is immediately moved via code.
Unfortunately the error still occurs intermittently, but at least it is simpler to reproduce.
Cheers,
--Mike--
|
|
|
Post by Luís Pedro Fonseca on Jan 5, 2022 21:33:29 GMT
Hi Mike,
Thanks for updating the project. However, can you please delete the file above and share it through PM so we don't leak the latest ProCamera2D version? Thanks
|
|
|
Post by mikeyj21 on Jan 17, 2022 11:40:17 GMT
Hi Luis!
Sorry to harass you, but have you had any progress with this issue?
Unfortunately I have got to the stage where my tester needs to play through a substantial portion of the game, but every time he will pick up an object or enter a menu screen (the two operations which set the timescale to and from 0), it runs the risk of the bug occurring, and ending the playthrough.
Cheers,
--Mike--
|
|
|
Post by Luís Pedro Fonseca on Jan 17, 2022 14:54:53 GMT
Hey Mike,
I'm really sorry but I haven't had the time to look further into this. I'll try to find some time this week.
Cheers
|
|