Issue with exported variables

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.

I may have posted too quickly. I restarted godot and the inheritance works as expected now.

1 Like

I know from my extensions to Project Boost that this is required in some circumstances when using inheritance. I built my levels using abstract templates (I1) that the finished levels (I2) would inherit from, but because I had 3 different rocket types with their own campaigns, I even went so far as to create an abstract-abstract template (I0) that the other templates inherited from.

  • Changes made to I1 would propagate to I2 without an issue
  • Changes made to I0 would propagate to I1 just fine, but would not propagate all the way to I2 without completely restarting the Editor if I remember correctly.

That’s one condition under which an Editor restart seems to be needed, and I’m sure there are more, as you discovered! Unfortunate that it frustrated you, but at least you’ll have a better idea how to attack [Export] problems in future =)

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms