In this godot video we are creating an exported variable for the sparks. I created this like in the video but instead in C#:
[Export] public PackedScene Sparks;
I then in the inspector build to get it to show up and added the Sparks.tscn to the variable using the Quick Load option. All good up to this point since it is no different than the other exported variables that all work just fine like weoponDamage, recoil, and fireRate. I saved all scenes and verified in the SMG scene that the Sparks scene was set in the exported variables. Run the game and I get errors every time I fire because Sparks is null. I banged my head against this for a good long while and added extra logging and then in my _Ready function I even resorted to adding:
if (Sparks == null)
{
GD.Print("Sparks is null, trying to preload");
Sparks = (PackedScene)ResourceLoader.Load("res://Assets/Weopons/Sparks.tscn");
}
This hack does fix the null problem but is not a real fix. After some more playing around I found that if I clear the sparks scene out of the hitscanweopon exported variable so it is no longer inherited and then specifically set it in the SMG scene variables it works and is not null. So it just doesn’t respect the exported scene being inherited. Is this a known bug in Godot 4.2.2? It is just weird that all the other exported variables work but this one.