0 votes

So, I have a GunTemplate scene & I made an AK-47 & a Glock-17 that inherit from it. They all share the same script & I found a problem; if I call a method on the AK-47 or Glock, like _ready(), it calls the method in both of them. How do I fix this? I tried setting ‘Local to Scene’ on in the shared script, but that didn’t work.

Godot version 3.3.3
in Engine by (59 points)

1 Answer

+1 vote
Best answer

If you want specific code for your inherited scenes, you should extend the parent script. Pseudocode:

Parent

_ready():
    do_stuff()

Child

extends "res://path/to/parent.gd"
_ready():
    ._ready() # Call parent's _ready()
    do_child_specific_stuff()
by (1,311 points)
selected by

Thank you, I never new I could do this!

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.