Error Class "name" hides a global script class

Godot Version

4.6.3

Question

Hello, I was just putting my car scene into another scene and I keep on getting this error, Error: Class “RaycastCar” hides a global script class. I have looked it up and I don’t get how to fix it. Should I just delete the class name or put a 1 on the end of it so that is different? Also I am very sure that this is the only script and is not a duplicate.

Here is the code it is kinda long and calls to another script a lot.

extends RigidBody3D
class_name RaycastCar

@export var wheels: Array[RaycastWheel]
@export var acceleration := 600.0
@export var max_speed := 20.0
@export var accel_curve : Curve
@export var tire_turn_speed := 2.0
@export var tire_max_turn_degrees := 25

@export var skid_marks: Array[GPUParticles3D]
@export var show_debug := false

@onready var total_wheels := wheels.size()

var motor_input := 0
var hand_break := false
var is_slipping := false

func _get_point_velocity(point: Vector3) -> Vector3:
	return linear_velocity + angular_velocity.cross(point - to_global(center_of_mass))

func _unhandled_input(event: InputEvent) -> void:
	if event.is_action_pressed("handbreak"):
		hand_break = true
		is_slipping = true
	elif event.is_action_released("handbreak"):
		hand_break = false

	if event.is_action_pressed("accelerate"):
		motor_input = 1
	elif event.is_action_released("accelerate"):
		motor_input = 0

	if event.is_action_pressed("decelerate"):
		motor_input = -1
	elif event.is_action_released("decelerate"):
		motor_input = 0


func _basic_steering_rotation(wheel: RaycastWheel, delta: float) -> void:
	if not wheel.is_steer: return

	var turn_input := Input.get_axis("turn_right", "turn_left") * tire_turn_speed
	if turn_input:
		wheel.rotation.y = clampf(wheel.rotation.y + turn_input * delta,
			deg_to_rad(-tire_max_turn_degrees), deg_to_rad(tire_max_turn_degrees))
	else:
		wheel.rotation.y = move_toward(wheel.rotation.y, 0, tire_turn_speed * delta)


func _physics_process(delta: float) -> void:

	var id := 0
	var grounded := false
	for wheel in wheels:
		wheel.apply_wheel_physics(self)
		_basic_steering_rotation(wheel, delta)

		if Input.is_action_pressed("brake"):
			wheel.is_braking = true
		else:
			wheel.is_braking = false

		# Skid marks
		skid_marks[id].global_position = wheel.get_collision_point() + Vector3.UP * 0.01
		skid_marks[id].look_at(skid_marks[id].global_position + global_basis.z)

		if not hand_break and wheel.grip_factor < 0.2:
			is_slipping = false
			skid_marks[id].emitting = false

		if hand_break and not skid_marks[id].emitting:
			skid_marks[id].emitting = true

		if wheel.is_colliding():
			grounded = true

		id += 1

	if grounded:
		center_of_mass = Vector3.ZERO
	else:
		center_of_mass_mode = RigidBody3D.CENTER_OF_MASS_MODE_CUSTOM
		center_of_mass = Vector3.DOWN*0.5

try swapping the 2nd line and the 1st one.

You probably have two .gd files with the same script, delete one of them.

I’m looking through my scripts and I only have one. When godot gives me the error it loads up a script that is a copy of the first one but it is called car-test.tscn::GDScript_sf7ru

Is that a temp file that godot makes when running that game?

Did you make the script (or a Node that the script is attached to) an autoload by accident?

Not that I remember, but i’ll looking into it and see if thats the problem.

Just looked and there isn’t anything in my globals tab, so it shouldn’t.

Ok, so i just somehow “fixed” the problem. What i did was just delete the script from the whole project and unattached all the scripts from the car, and added it again under a different name and it work. idk how and i’m not really trusting this to be a permanent fix but for now it works

That is the path format of a builtin script.

That’s an unfortunate bug. Sometimes Godot tends to re-save a script as a builtin script. In those cases you need to detach the builtin script and reattach the script from the file.

Some of those script duplication bugs were fixed in 4.6, but seems there are still some out there. Do you still recall which steps you did when this happened?

How the error came about in the first place or how i fixed it?

How it came about in the first place. I was involved with fixing some of those issues, so I’m interested in narrowing down further points of failure :slight_smile:

ok i will try best lol.

The scripts where from another scene and I was wanting the car on a different scene than the level (for organization), and I was moving over the scripts, mostly just copy and pasting it to another scene. After I did all of that no errors where happening when i ran it, so then I added the car scene to another scene. I then tried to run the scene that I moved the car into and that’s when I encountered the error.

(I hope this helps!)

I’ve had something similar happen when creating classes. It popped us as two different versions and it created some kind of conflict and caused issues where i would be unable to use the one i wanted. I deleted both, removed from all scenes used in and copy pasted the code into a new script. Then it just saved as one copy.