Unable to solve error with C#

Godot Version



I am following a tutorial about how to make a fps controller in Godot. The language that is used in the tutorial is GDScript but I prefer to use C#. I am trying my best to translate GDScript to C# but sometimes I just cannot figure out what to do even with a lot of research. The error I have encountered right now is this: Cannot modify the return value of ‘Node3D.Transform’ because it is not a variable [CS1612]. The lines of code that generates this error are:

public void _UpdateCamera(double delta)
mouse_rotation.X = tilt_input * (float)delta;
mouse_rotation.X = Mathf.Clamp(mouse_rotation.X, TILT_LOWER_LIMIT, TILT_UPPER_LIMIT);
mouse_rotation.Y = rotation_input * (float)delta;

	CAMERA_CONTROLLER.Transform.Basis = Basis.FromEuler(mouse_rotation);
	//camera_transform.Basis = Basis.FromEuler(mouse_rotation);
	CAMERA_CONTROLLER.Rotation.Z = 0.0f;
	//camera_rotation_z = 0.0f;
	rotation_input = 0.0f;
	tilt_input = 0.0f;

CAMERA_CONTROLLER.Transform.Basis = Basis.FromEuler(mouse_rotation);
CAMERA_CONTROLLER.Rotation.Z = 0.0f;

these two lines of code from this function.
CAMERA_CONTROLLER is just a Camera3D.

I have researched how I can solve this for hours and tried quiet a lot of different ways to solve this. But I was unable to sadly. Any help is appreciated.

Transform3D in C# seems to be a struct, so this is a genuine C# compile error and not an error in godot.
CS1612 document would be helpful.

1 Like

Thank you for your reply and I have taken a look at the documentation about this error. Sadly though my C# knowledge was not sufficient for this. I still am not really aware of what I am supposed to do.

I am not sure but does this work?

Transform3D newTransform = CAMERA_CONTROLLER.Transform; // Copy the value
newTransform.Basis = Basis.FromEuler(mouse_rotation);   // Modify the value
CAMERA_CONTROLLER.Transform = newTransform;             // Rewrite the value

In my understanding of structs, when we write CAMERA_CONTROLLER.Transform in script, this does not mean the exact object which the variable CAMERA_CONTROLLER.Transform has. It is the copy of the object which CAMERA_CONTROLLER.Transform has.

1 Like

Again thanks for the reply. Hmmm. Now I get a null reference exception error at the first line of code you gave me. I have made the same thing for the rotation as well and got the same error. If you want anymore details please ask.

Hmm, I think nullable object in the line is CAMERA_CONTROLLER only, because Transform is struct (I believe it is not nullable). Is it assigned properly?

1 Like

Sir, I am really sorry for wasting your time with my ignorance.

I had declared the CAMERA_CONTROLLER as an export variable so I had to just assign it the editor. As someone coming from Unity I am ashamed about how I was so blind about this.

My goal was to be able to look around with the mouse. I still does not work properly but I get no errors now at least.

As I said I am really sorry about wasting your time. And I do not want to waste it any further. But if you want to help further I would appreciate it.

No worries. We game developers spend so much time on these things anyway!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.