+1 vote

Greetings. I'm a newbie in Godot, and I only programmed used structured programming (instead of OOP) before, so it's been hard to assimilate some Godot concepts.

Well, I'm now programming a quick Asteroids like prototype. I have three scenes for it:

  • A Main scene.
  • A Ship scene.
  • A SmokeParticle scene (I programmed it as a smoke sprite growing and getting more transparent, that I'll use for smoke particles emitted by the ship).

So, first I programmed the Ship scene and its movement, then I programmed the Main scene, that includes the Ship and a Camera node that follows the ship, and now I want to include the Ship scene code to add instances of the Smoke scene. Problem is that Godot cannot recognize add_child(SmokeParticle) (Parse error: identifier not found: SmokeParticle). What should I do so it could recognize a node from an external scene in my code?

Thanks in advance!

in Engine by (106 points)
edited by

1 Answer

+6 votes
Best answer

Hi, you need to load the scene as a resource first.

#Load the resourse using preload
const MySmokeResource = preload("res://SmokeScene.tscn")

func _ready():
    #Make instance
    var GrabedInstance= MySmokeResource.instance()
    #You could now make changes to the new instance if you wanted
    CurrentEntry.name = "SmokeA"
    #Attach it to the tree

The development branch documents has an updated resource entry: https://docs.godotengine.org/en/latest/getting_started/step_by_step/resources.html?highlight=resources
This explains resources better than the old documents.

by (1,443 points)
selected by

Thanks, it worked! :)

What is CurrentEntry in your example? Should that be GrabbedInstance?

No idea, I (like so many other developers) abandoned Godot a long time ago.

I think you are correct because that is how I used it here: https://www.reddit.com/r/godot/comments/9vrvpr/best_method_for_generating_content/
That is what Google tells me.

Man, I had so much hope for this engine back then.

Why have you bounced off it @MysteryGM? I've been using it for a game jam this past week or so, and while it hasn't kept up with some of the progressions in Unity, it still has good aspects. I would have liked some of the pointier edges to have been fixed in the 2 years since I used Godot last 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 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 webmaster@godotengine.org with your username.