Misunderstanding scenes

1000h1000h Posts: 127Member
edited August 2016 in Programming
So it seems that in the nature Godot it is implied that each, what I would call a completed asset, should basically have its own scene... One for each weapon model, one for each character, one for each enemy... etc etc



I see with Godot in order to preload scenes and instance them, I write essentially this:

var scene_x = preload(scene_x.scn)
scene_x.instance()

which, I'm pretty sure, instances EVERYTHING in the scene.  How do I instance a single object from a scene that has been preloaded instead of everything in the scene, so that I don't have to have x many scenes for x many models?

I basically want to write this:

mainscene.add_preloaded_object("name of object",<add_to_this_location>)

Answers

  • BinaryOrangeBinaryOrange Posts: 118Big Boss
    I take it from the strikeouts you figured out a solution to your problem? :smile: 

  • AvencherusAvencherus Posts: 49Member
    Answer ✓
    Yes, I had similar confusion, I suspect most do.  I think the name "scene" is a little misleading, at first glance you kind of think it is a game area like a level, a workspace that is exclusively dedicated to creating scenes.  They're more like containers of some kind, ones that can be instanced.

    You could have your game assets as a collection of nested nodes that you may hide and unhide in a single scene, but that isn't very flexible.  But the way that scenes and nodes work, you have quite a number of ways you can decide to organize your game.
  • RossRoss Posts: 199Member
    edited August 2016 Answer ✓
    1000h said:
     . . . each, what I would call a completed asset, should basically have its own scene... One for each weapon model, one for each character, one for each enemy... etc etc

    Definitely. Any object that you might want to use more than once should be it's own scene.

    You can organize stuff however you want (that's the point of the scene system), but in my experience it pays to break things down into pretty small chunks. It's also kind of essential if you're working in a team: source control gets a bit tricky if multiple people edit the same scene at once.

    You can make every self-contained piece of stuff it's own scene. For example I have a platformer project with a little guy carrying a sword. The player character is one main scene with a master script for handling physics, movement, input, etc, and communicating with the sub-scenes. Inside that is a scene for the rig with all the sprites and animations, a scene for the health bar with its own animations and stuff, and a scene for the camera. The rig in particular has dozens of nodes, so keeping that separate from everything else has prevented a lot of headaches.

    I often make separate scenes for each special effect. I like to work on them without distractions and then I can easily stick them on anything I want or spawn them dynamically. They usually have a couple Particle emitter nodes, a few sprites, an animation player or two, and a simple script to control it with. Say you wanted a machine to spark when it gets hit. You could make a scene for the spark effect, drop it onto the machine, and whenever the machine's script detects a hit, call a "go()" function on the spark effect. Then you could make any object spark by adding one scene and one line of code. And if you want you could always customize the effect for one particular object by checking "editable children" and tweaking things. 
  • BinaryOrangeBinaryOrange Posts: 118Big Boss
    Answer ✓
    The easiest way I remember how scenes work is that they are essentially a more advanced version of Unity's Prefab system. 

    In Godot, a scene is the general-purpose containter. You can use a scene to store the components that make up your player, enemies, NPCs, objects, event triggers, etc.,. It's truly an endless list. 

    In order to keep myself organized in my project, I do something like this. 

    - Create a "Scenes" folder
    - Create a new subfolder within "Scenes" for "Characters", "Objects", "Event Triggers", and finally "Levels". 

    That way, I know instantly what are actual scenes/levels, and which are just containers for re-usable assets. 

    I certainly agree that the documentation could be a bit clearer on this feature, as it is really confusing when you first start learning Godot. UItimately, this feature alone is what drew me to Godot the most - it's a very robust system and can let you do anything once you learn how to utilize it to its full potential. :smiley: 



  • 1000h1000h Posts: 127Member
    Glad to see you guys were understanding, it seemed so obvious once it clicked.  I have been prototyping a game in blender and want the build capabilities and stand alone exe export capability of Godot, and trying to readjust my brain to this.


Sign In or Register to comment.