how do i create 2 seperate scripts for inherited scenes??

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By godotisgreat


I was following a tutorial (see above), and i decided to expand the game by creating multiple scenes. I wanted things to be simpler and quicker so i created an inherited scene of the main scene and then cleared the inheritance. For some reason, the scripts in the scenes are linked to the scripts of the other, inherited scene (example: script_1 of the main scene is linked to script_1 of the inherited scene).

When i mean ‘linked’, i mean that when i updated one script, the other script of the other scene is updated to match the scripts. I thought clearing inheritance would stop this but it was not the case. Can someone guide, help, or tell me what im doing wrong? I am new to godot and dont know alot about the game engine.

What i want is that both the scripts are seperate and stop updating or matching.
Your help is appreciated alot, Thanks

:bust_in_silhouette: Reply From: Inces

Sripts is a resource, that scene uses. Resource class is created to be shared amongst many nodes. If You want disinherited scene to have its own script, You can only remove current script and assign a new one. If inheritance is cleared, original scene will be left with original script.

Thanks alot, I understand that more clearly now!

godotisgreat | 2022-08-18 09:57

:bust_in_silhouette: Reply From: SnapCracklins

What you probably SHOULD be doing is some sort of class system. I am not sure what your scripts are doing, but if you want some of them to share functions and then want those functions to change, make a class_name script with those base function and then write new scripts to each object so you only inherit what you need. For example, let’s say you have a door object that opens and closes:

extends Area2D

class_name DoorDefault

func _open():
##### some function here

func _close():
#### another function here

An advantage of this is then when you create new scenes, you can have them start with this script attached. Then you’re not repeating code.

Then in inheritors:

extends DoorDefault

func _custom_function():
### custom function here

One caveat of this: be careful that you don’t run into the “Deadly Diamond” of inheritance, where two nodes inherit from one node, then another node inherits from those because this can cause a LOT of problems. (Example: A inherited by B and C, then D inherits B and C.)

Thank you for your comment. This helped me expand my program and you made me aware of why the problem was occuring. To be honest, i already had problems such as what you call the “Deadly Diamond” but thanks for letting me know.

godotisgreat | 2022-08-23 10:01