I have a weapon scene which launches a projectile scene, but retains a reference to that instanced node, so the second time the player hits "fire", the launched projectile explodes into smaller projectiles.
When I scale up the number of NPCs shooting these projectiles, I pretty consistently (but not always) get a strange issue where that variable in the "weapon" that points to the last_shot projectile is pointing at a different projectile node of a different scene type that shares the same base class of Projectile.
Here is the "weapon" scene code, with the variable in question being "lastshot", and the exception being an error because the "lastshot" node does not have the "explode" method (because it has somehow changed to point at a different projectile.
var energy_use = 35
var fire_delay = 0
var fire_delay_time = 0.75
var projectile_type = preload("res://Weapons/Projectiles/BlasterBeam.tscn")
onready var shoot_effect = $ShootAudio
onready var explode_effect = $ExplodeAudio
var energy = 0
if last_shot != null and is_instance_valid(last_shot) and last_shot.traveled > 30:
last_shot = null
if fire_delay <= 0 and energy_available >= energy_use:
var projectile = projectile_type.instance()
last_shot = projectile
fire_delay = fire_delay_time
energy = energy_use
fire_delay -= delta
In terms of inheritance, i do have an inherited "spawn" method from Weapon that different weapons use to place / position / add_child the new projectile. The projectiles also inherit from a common base that extends Area.
I don't refer to or access the "last_shot" variable anywhere outside of this script or scene.
Any help or ideas on how to debug would be greatly appreciated! If more code is needed to fully understand, please also indicate! Thanks!