• Godot Help
  • Complicated scene reuse with different scripts?

I have a tank that I create and load all the collisionshapes for in code. It seems to work great but takes quite a while (a couple seconds) to load. I see needing several copies at once but doing that load several times seems too long and quite unnecessary.

Is there a way I can make that tank instance then copy it a few times and change the script that controls it? I don't want each copy to re-load the meshes for colliders etc, I want a copy of it already finished all that but is it's own instance so I can change values in it without changing all the other copies. If I just use tank.instance() then it calls _ready() and loads everything again. If I just say copy tank then it's just pointing at the same instance as far as I know. If I change the script controlling it (which would extend the original script rather than replace it) will that wipe all the loaded data?

Seems like a toughie but everything I've done in Godot that looked tough was actually a breeze so far.
Thanks for any help

    patm if you just want to change values (like say speed or power) without changing scripts, consider the 'export' function so you can change the script's values only for that instance in the scene. So have your objects loaded, then change them in the editor one by one. No recoding necessary.

    export var speed = 100
    export var power = 100

    Then that object can be edited here:

    I can't see how changing values in the editor helps me to make distinct copies of the instance without _ready() being called which loads all the meshes and creates the colliders while running.

    I want to do the equivalent of:
    var TankBase = preload("the scene file")

    func _ready():
        aitank = TankBase.instance()
        playertank = playertank.copy() # So _ready() doesn't run again
        playertank.controlscript = playerscript (without wiping out everything loaded by aitank)

    aitank and playertank both have all the colliders loaded and built in code but player tank gets extra script commands for movement etc. I can do it by creating two different scenes and instancing those but both would need to load meshes from disk etc. If the game has 20 different vehicles that means a LOT of loading time. I would rather load each one once and make copies with different scripts controlling them

    Well I was loading meshes and creating colliders in code but I finalized how the colliders will be (and how many) so I decided to create a "blank" tank scene that I will copy for each different one and set all the different colliders manually as well as change the placement of Position3D nodes for Cameras I will add in the player script. Now I just need to figure out how to change the script for an instance of a scene.

    That works well and changing the script was dead simple
    player = Base.instance()
    player.set_script(load("res://myscript.gd")

    Just can't seem to activate a camera inside that instance.