- Home /
Window flicker when moving camera
Hi people, I'm having a lot of trouble with something.
I have an ortographic camera, which when given the conditions I move to another point from one frame to the other. This means the movement is instantaneous and should not give any kind of problem.
The problem is, that whenever I press the button which moves the camera from a fixed point to another, there is a 1ms (just to say) flicker. This flicker is like a black screen that lasts 1 frame, and sadly enough to perceive with the eye.
Does anyone know something about this? A workaround? A fix?
Thanks very much!
Can you provide a code sample? It's hard to debug this type of problem without looking at the exact methodology.
@dkNinja : Of course, the script is as it follows:
// We add the camera var gameCamera : GameObject;
// We list all the Scenes in the Game. var Scene1 : GameObject; var Scene2 : GameObject; var Scene3 : GameObject;
function changeScene(id : int){
switch(id){
case 1:
// Scene 1
gameCamera.transform.position = Scene1.transform.position;
break;
case 2:
// Scene 2
gameCamera.transform.position = Scene2.transform.position;
break;
case 3:
// Scene 3
gameCamera.transform.position = Scene3.transform.position;
break;
}
}
As you can see, the movement is given by a changeScene function which is called from the OnClick callback of a Box Collider acting as a button. So there's no Update nor LateUpdate function available.
I seem to remember someone else having pointed this out on this question. However, I think the problem is that the change of the Camera position happens in the middle of the event loops before rendering the camera.
http://unity3d.com/support/documentation/$$anonymous$$anual/Execution%20Order.html shows that colliders are handled in the physics loop. Try to set a flag to make the move in the collider OnClick callback and actually make the move in a LateUpdate. This keeps the camera calculations that have been done up until now from being invalidated.
Let me know if this doesn't work. I'll try to replicate the problem on my project, then.
@dkNinja I'm sorry I have to say this out loud, but I really don't know anything about flags. I do understand what you say about the colliders being handled on the physics loop, but I don't know what to set a flag means.
Could you enlighten me a little about this so I can test it? Your help is much appreciated.
@dkNinja Thank you very much, I will test it right away and let you know any updates!
Answer by dkNinja · Apr 13, 2012 at 07:24 PM
No problem, flags are just a fancy way of saying a global variable. You could do something like:
var newScene : int = 0;
function changeScene(int id) {
case 1:
case 2:
case 3:
newScene = id;
break;
}
function moveCamera() {
switch(newScene){
case 1:
// Scene 1
gameCamera.transform.position = Scene1.transform.position;
break;
case 2:
// Scene 2
gameCamera.transform.position = Scene2.transform.position;
break;
case 3:
// Scene 3
gameCamera.transform.position = Scene3.transform.position;
break;
}
}
function FixedUpdate() {
if (newScene != 0) {
moveCamera();
}
}
Something of this sort may prevent the flickering.
Edit: You would still call changeScene from other code to move the camera. Then this script would take care of delaying the call until the end of the frame.
Edit: Changed LateUpdate to FixedUpdate as pointed out by @kevinseligmann
Thank you VERY much for your help @dkNinja this surely helped me understand a little bit more about how Unity works. Thanks!
Answer by JayMHelpsU · Apr 13, 2012 at 04:09 PM
The only thing i can think of is the refresh rate or the texture quality. Either one of those could be causing the flickering, try editing some values maybe in the 'Render Settings' I hope this helps, let me know the results. :)
@$$anonymous$$$$anonymous$$HelpsU I couldn't fin anything on Render Settings that would help me with this. The odd thing is that it really doesn't matter the texture quality, as my texture is child of the camera. I mean, the texture doesn't move if the camera doesn't.
I think I will try to fade in/out everytime I have to change the active window, to see if that solves the problem. But, it's not the best solution at all.
Your answer
![](https://koobas.hobune.stream/wayback/20220613070248im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Move the camera when the mouse reaches the edges of the screen 1 Answer
Game view is suddenly black 5 Answers
Flickering screen when development build disabled 0 Answers
Jerky Camera and Varying Translate speeds 1 Answer
Moving (teleporting) player and camera when they enter a certain area 5 Answers