I'm trying to create a character, which consists from different body parts (body, head, arms, legs etc). There can be different types of same body part, e.g. normal arms, wooden arms, metal arms. The idea is to modify character parameters based on the type of each body part (lets say metal arms allow to pick heavy objects but reduce jumping height). I have a following setup (for simplicity lets just use character and arms entities)
BaseCharacter scene with
BaseArms scene with
MetalArms scene with
MetalArms scene inherits
BaseArms scene, same for scripts,
Next, I want to instance character body parts from code (so later they can be changeable at runtime). I've got some programming background and at first I've decided to use Dependency Injection (DI). With DI I just modify character
_init to have
_arms: BaseArms parameter and then can create characters passing needed arms, which all inherit
BaseArms.gd. That works just fine but only with scripts. Is there a way to use some kind of DI with scene instancing? Since if arms have not only behavior attached (scripts), but also some appearance (like
BaseArms scene has
AnimationPlayer child nodes), then it doesn't work like that. I've tried to resolve this issue by preloading body parts and instancing them in
_init method, but then I have hard time using their behavior.
So the questions are:
1) Can I instance scenes with their scripts (which inherit some base scenes and scripts) in another scenes and have access to both scene nodes and script properties/methods
2) Is there a way to use DI like principle to instance scenes?
3) If I use scene instancing like the following, how to get the attached scene script?
we are in character script, say _init method
var arms_scene = preload("res://MetalArms.tscn")
self.arms = arms_scene.script? how to get this to work
Thanks a lot!