The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

0 votes

I am making a 2D shooter with Godot .mono and I have the following structure for my main scene and "player":

Node2D (main scene node)
|CanvasLayer
|
TextureRect
|_KineticBody2D (player node)

The player scene instances a packed scene for my "bullet":

[Export]
public PackedScene PhaserBurst;

private AnimatedSprite _sprite;

public override void _Ready()
{
    PhaserBurst = GD.Load<PackedScene>("res://Game/Weapons/MechProjectiles/IntroMech/IntroMechPhaserBurst.tscn");
    _sprite = GetNode<AnimatedSprite>("IntroPlayerSprite");
    var burst = (Area2D)PhaserBurst.Instance();
    AddChild(burst);
}

When I run the player scene by itself, everything works perfect. However, when I run the main scene, which has the player as a child, everything works except the PackedScene being instanced. It's not just a matter of the position being off screen, printing to the console during the instantiation confirms that there is no PackedScene while running the main scene.

I've tried adding the instance as a child to every node in the parent scene tree, but no luck. Though I'm using c sharp, I would appreciate any input even for gdscript (I'm a .NET developer, so switching the syntax to c sharp hasn't been too difficult). I'm also very happy to add anymore context/code/screenshots needed to get me pointed in the right direction. I really appreciate any input!

Godot version 3.3.4
in Engine by (19 points)

Hey zel,

do you get an error message?

Nope! But I actually fixed this, I'll respond below. Thanks for responding!

2 Answers

0 votes
Best answer

I actually fixed the issue, and it wasn't due to the export. It was actually much sillier than that and a big oversight in my debugging.

Basically, the packed scene is being instanced every time my player hits the "ui_select" Input. Initially, I had this logic in an Unhandled Input event handler(per the tutorial I was following). It worked for running the player scene by itself, but once I had the player as a child in another scene, the event wasn't even being detected. Moving it into a normal if statement inside of _Process actually triggers the instance now:

public override void _Process(float delta)
{
    HandleMovement(_sprite);

    if (Input.IsActionPressed("ui_select") && PhaserCooldown.IsStopped())
    {
        FireIntroMechPhaser();
    }
}
by (19 points)
+1 vote

It feels like issue with export keyword. Perhaps You forgot, that You exported other variable type than packedscene in your main scene player ? Anyways, since You hardcode packedscene in ready function, try to get rid of export keyword above.

by (8,188 points)

I actually fixed the issue, and it wasn't due to the export. It was actually much sillier than that and a big oversight in my debugging.

Basically, the packed scene is being instanced every time my player hits the "ui_select" Input. Initially, I had this logic in an Unhandled Input event handler(per the tutorial I was following). It worked for running the player scene by itself, but once I had the player as a child in another scene, the event wasn't even being detected. Moving it into a normal if statement inside of _Process actually triggers the instance now:

public override void _Process(float delta)
{
    HandleMovement(_sprite);

    if (Input.IsActionPressed("ui_select") && PhaserCooldown.IsStopped())
    {
        FireIntroMechPhaser();
    }
}

Thanks for responding though!

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.