Godot Version
4.4.1 | C#
Question
4.4.1 | C#
I am trying to resolve an error that my debugger keeps throwing when a Tween animation is being run. The tween runs fine, but everytime its runs, the debugger throws 12: “step: Tween (bound to /root/Level/CameraBase): started with no Tweeners.” errors. I’m not sure why this is happening.
My code is the following:
public override void _Process(double delta)
{
rotateCameraBase(delta);
}
private void rotateCameraBase(double delta){
if(!cameraCanRotate || !cameraIsRotatingBase ){
return;
}
Vector3 targetRotation = Rotation;
Tween tween = CreateTween();
if(moveCameraLeft){
targetRotation.Y += Mathf.DegToRad(90f);
tween.TweenProperty(this, "rotation_degrees", targetRotation, 2.0f);
moveCameraLeft = false;
}
if(moveCameraRight){
targetRotation.Y -= Mathf.DegToRad(90f);
tween.TweenProperty(this, "rotation_degrees", targetRotation, 2.0f);
moveCameraRight = false;
}
}
I recommend moving the creation of the tween outside of that function, and instead, put it in ready. Create a private variable for the Tween, and re-use it inside your rotateCameraBase
function.
No need to create a new tweener each time, especially when this function gets called every tick, that’s really expensive.
1 Like
If you aren’t moving camera left or right then you’ve created a tween with no function or “Tweeners”.
Maybe it would be better for you to use if/else if, or best to use a signal rather than checking these moveCamera bools every frame?
private void rotateCameraBase(double delta){
if(!cameraCanRotate || !cameraIsRotatingBase ){
return;
}
Vector3 targetRotation = Rotation;
bool moved_camera = moveCameraLeft || moveCameraRight; // copy if either moved
if(moveCameraLeft){
targetRotation.Y += Mathf.DegToRad(90f);
moveCameraLeft = false;
}
if(moveCameraRight){
targetRotation.Y -= Mathf.DegToRad(90f);
moveCameraRight = false;
}
if (moved_camera) { // only make a tween if moved
Tween tween = CreateTween();
tween.TweenProperty(this, "rotation_degrees", targetRotation, 2.0f);
}
}
1 Like
The documentation says reusing a tween is undefined behaviour.
1 Like
You’ll have to use more words. In that example the tween is killed and a new one is created, just like the documentation says you should do.
1 Like