- Home /
Missing objects
Hello guys!
First of, I'm a total noob of creating games and I'm about to create my first one.
I think my unity is glitching or I rather know. Some objects like bushes sometimes disappears, objects seems to be over one more layer when they are supposed to be under. These things happen in the scene and when I start the game, everythings turns back to normal. My characters speed changes over time, I have my normal speed virable set to 7 but now when I come back to unity, 7 is way to slow and have to increase it to around 55 to be able to get the same speed as before. After some time though the speed goes back to normal and 55 becomes waay to fast.
So I can probably think it takes some time for unity to get warmed up? If this is the case then how can I get it to work faster?
One more thing is when I walk with my character, sometimes when I walk left or right my characters goes under some layers all of a sudden. This happens only sometimes and sometimes everything works fine. And I just created another room in my 2D game and in that room when I go left my character disappears but it still walks.
Is there anyone here that knows how to fix this? I hope that I explained it good enough for people to understand what I'm dealing with here. xD My specs on the computer im using is: processor: AMD Ryzen 7 5800H with Radeon Graphics 3.20 GHz Graphic card: NVIDIA GeForce RTX 3080 Laptop Ram: 16gb
Those can be caused by a lot of things, I guess. So it's kinda hard to know. First of all, for the disappearing sprites, that could be caused by clipping. If the Z values of the sprites are too close, they will clip and behave weirdly. So check that out, if altering the Z values help with that problem. And for the speed changes overtime, try moving the movement to FixedUpdate() rather than Update(), and use Time.fixedDeltaTime for calculating speeds and such. Not sure if that will work, but it's worth a try, I guess. Are you moving your character with ApplyForce()? I'm moving my character with that method, and I'm having the same problem as you are, but I'm working on 3D enviroment. Now for the walking left and going under layers, that could also be caused by moving with ApplyForce(), because if you apply one wrong force in one frame, your character could move in Z axis, and that would just mess up the whole thing. And again, if the new room you created is in a different height, your character will disappear when walking into it. TL;DR 1- Sprites could be disappearing randomly because of changes in the Z-axis 2- Try moving your movement to FixedUpdate() rather than Update(), and use Time.fixedDeltaTIme in your calculations. That COULD fix the movement speeds 3- The room problem could also be caused by changes in Z-axis, so check that out
hope that helps, if not just ask
Did change to FixedUpdate() and also changed Time.FixedDeltaTime and so far it seems have solved the issue with the moving speed. I played around with the sorting layers and re-did some things. And now everything works fine. But I will keep the z-axis in $$anonymous$$d when problems like this appear.
Thanks for your reply m8.. Really appreciate it :)
unity does not need to warm up, the discrepancy in speed is probably caused by lag or other things taking up memory, what you need to do is tie speed into time, so you would do speed*Time.deltaTime or Time.fixedDeltaTIme if in fixed update, when applying speed in your code.
Yeah I did this and so far it works! Thanks man for you reply :)
Answer by Duzo · Jan 20 at 12:48 PM
I solved it for now.. It had to do with sorting layers xD.. All though the character speed differs from time to time and when the character walks it is a bit choppy.. Is it possible it is just the unity engine that is slow and will work as it should when you make it into an actual application?
I still think there are some settings that could make unity work faster or peform better? If there are then please tell me what settings are recommended!
How are you moving your character? Are you remembering to multiply by Time.deltaTime when doing so?
Yeah I multiply the speed with Time.FixedDeltaTime now... Had Time.DeltaTime before and I think this was the issue.