0 votes

Tutorial: https://www.youtube.com/watch?v=0713nlQxU7I
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: script1 of the main scene is linked to script1 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

Godot version Godot 3.4 , GLES2
in Engine by (26 points)

2 Answers

0 votes

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.

by (7,925 points)

Thanks alot, I understand that more clearly now!

0 votes

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.)

by (548 points)

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.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.