'Class "Name" hides a global script' error

Godot Version

Godot 4

Question

‘Class “Name” hides a global script’ error. I’ve looked around but can’t seem to really understand the solution. I’m currently making a second enemy and have used a “damageable” class name when the enemy is taking damage from the player. I want to reuse this script for my second enemy but get the error ‘Class “damageable” hides a global script’.
Don’t really know how to proceed from here.
Any and all help is appreciated

You can’t have two files that have the same class_name. You can make a base class with class_name damageable, then have your two enemies extend the base class.

How do i extend the base class? Is it just class instead of class name?

Every script starts with extends ___ in your case the script you want to extend is damageable.

extends damageable

This keeps all of the properties and functionality from the last script, you might not want to extend it, but instead use the same script.

2 Likes

In your subclass, use extends damageable

1 Like

Should my base class be seperate from both my enemies or can I just extend my second enemies script from the first?

Always make separate files for separate entity types, then instance them for each enemy of that type you have in your level.

1 Like

Thanks for the help :slight_smile:

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