Godot 4 | scene manipulation (hiding and removing scenes)

Sdílet
Vložit
  • čas přidán 22. 08. 2024
  • The video goes over hiding and removing a scene in Godot 4,
    and the difference between them.
    #godot #gamedev #gameengine

Komentáře • 43

  • @diynevala
    @diynevala Před měsícem +1

    The SceneTree animation with sound felt like the Mini Metro aesthetics! I Love it!

  • @BonesMcoy
    @BonesMcoy Před 28 dny

    These short videos are so good. You're gonna have a lot of subscribers very soon with this quality and intuitive break downs.

  • @MonkiGowst
    @MonkiGowst Před rokem +10

    This was so helpful!

  • @Fylart75
    @Fylart75 Před 3 měsíci

    oh i think this relates to my question in your first video whereas its a part of the scene but not a child of it so we need to add it as a child. Thank you thats very clear

  • @snaker90
    @snaker90 Před 3 měsíci

    This is exactly what I need, so clearly. Thank you!

  • @alexxgg9208
    @alexxgg9208 Před měsícem

    underrated channel

  • @wulfrickwille3871
    @wulfrickwille3871 Před rokem +3

    Well explained :)

  • @serghonest9
    @serghonest9 Před rokem

    Impressive, thank you so much!

  • @ocococococococococococococ3267

    Ty so much, new dev on godot coming from unity this really help. Is there a way to get the same color of your editor? On unity i had a theme with similar color so i really like it

    • @JumboGamedev
      @JumboGamedev  Před 3 měsíci

      You are very welcome. Yes, you can go to editor, then editor settings, then theme, then use 11124b for the base color, and use ff0090 for the accent color.

  • @editdev
    @editdev Před 10 měsíci

    Awesome video, thanks for sharing your godot knowledge. I'm curious, do you by any chance use Motion Canvas to make these videos?

    • @JumboGamedev
      @JumboGamedev  Před 10 měsíci

      Thank you very much! No, I don't use Motion Canvas.

  • @BLACK-NIGHT-dg1ow
    @BLACK-NIGHT-dg1ow Před měsícem

    Soo i making a game and i want to change scenes without closing it and i dont know how

    • @JumboGamedev
      @JumboGamedev  Před měsícem

      If I understand correctly, you want to preserve/save the changes that happened in a scene (eg. changes in positions of each node), and when you switch back to this scene you want to continue from where you left off. In this case, it is best to detach/remove the root node of your scene instance, and attach it back when you want, using add_child.

  • @agriasoaks6721
    @agriasoaks6721 Před rokem +2

    Sensei,
    Is this how map/level changes in rpg games?

    • @JumboGamedev
      @JumboGamedev  Před rokem +5

      Yes, usually we will remove/detach the scene of the current level, and then replace it with another one. But most of the time
      you want to use queue_free() after removing the scene to release the resources occupied by the removed level.
      A better way to do it is to use change_scene_to_file
      or change_scene_to_packed (they will remove the
      current scene, free it, and then add the new one for you). I might do a video about them : )

    • @agriasoaks6721
      @agriasoaks6721 Před rokem

      ​@@JumboGamedev Yes please!

    • @raysandrarexxia941
      @raysandrarexxia941 Před 6 měsíci

      @@JumboGamedev the change scene methods don't actually delete the old scene. They are still in memory and it's causing problems with my game.

    • @JumboGamedev
      @JumboGamedev  Před 6 měsíci

      @@raysandrarexxia941 According to the documentation, they delete the current scene.
      From the documentation: "We can delete the existing scene. SceneTree.change_scene_to_file() and SceneTree.change_scene_to_packed() will delete the current scene immediately."
      Source: docs.godotengine.org/en/stable/tutorials/scripting/change_scenes_manually.html
      Maybe try using .free() as the documentation says.

  • @solitary200
    @solitary200 Před rokem +1

    Can you do a video on loading screens?

    • @JumboGamedev
      @JumboGamedev  Před rokem +1

      Yes, for sure. I will try my best to do it soon : )

  • @ser-pzdts
    @ser-pzdts Před 6 měsíci

    i have a problem with .show() .hide() when node is a scene my code doesn't work properly But when its a @editible children(in scene) it works... But not when its not editible scene (22/02/24) p.s. thanks for remove_child() p.s.2 Nope even remove_child() doesnt help

    • @JumboGamedev
      @JumboGamedev  Před 5 měsíci +1

      If you are invoking .show() .hide() on the packedScene (the resource returned by load/preload), then this won't work. You need to invoke .show() .hide() on the node that is returned when you instantiate the scene.

    • @ser-pzdts
      @ser-pzdts Před 5 měsíci

      @@JumboGamedev""on the node that is returned when you instantiate the scene." sounds difficult for me Anyway thanks for response

    • @ser-pzdts
      @ser-pzdts Před 5 měsíci

      deepai ""In Godot, when you instantiate a scene, a node called the "root node" is returned. This node represents the top-level parent of all nodes within the instantiated scene. It serves as the starting point for accessing and manipulating other nodes and components within the scene hierarchy. By interacting with the root node, you can dynamically add, remove, and modify nodes and their properties within the scene." oookey But always used root source node... yes or not

    • @JumboGamedev
      @JumboGamedev  Před 5 měsíci

      @@ser-pzdts
      You are welcome!
      Let's look at it this way:
      var packedSceneRef = load("res://path/to/scene.tscn") # this is a packed scene
      var sceneRootNode = packedSceneRef.instantiate() # this is the root node of the scene (this root node and its children have an identical structure to the scene you defined/instantiated)
      add_child(sceneRootNode) # this will attach the (root) node as a child to the node that has the script attached.
      sceneRootNode.hide() # this will hide the (scene) root node and its children.
      You can also access children nodes of the sceneRootNode and hide them independently.
      I think these 2 videos may be helpful:
      => czcams.com/video/um2dqyH-_YE/video.html
      => czcams.com/video/h7lg-gpb5H4/video.html

    • @ser-pzdts
      @ser-pzdts Před 5 měsíci

      @@JumboGamedevIm not using code to instantiate the scene pack Im using just mouse-interface panel. The absolute path of the scene pack im getting by click and drag the node (feature)...

  • @DoubledEthan
    @DoubledEthan Před 3 měsíci

    How to reattach in code?

    • @JumboGamedev
      @JumboGamedev  Před 3 měsíci

      You can use add_child() or add_sibling() to reattach a node back to the scene tree.

    • @DoubledEthan
      @DoubledEthan Před 3 měsíci

      @@JumboGamedev what's the difference between add child and add sibling

    • @JumboGamedev
      @JumboGamedev  Před 3 měsíci +1

      @@DoubledEthan add_child() adds a node as a child of another node, while add_sibling() adds a node at the same level as another node (ie. it becomes a child of the same parent).

  • @granmastern
    @granmastern Před 4 měsíci

    I'm guessing removing a child is different from queue.free?

    • @JumboGamedev
      @JumboGamedev  Před 3 měsíci

      Removing a child node detaches it from its parent but keeps it in memory (ie. the node is there, but it is just not attached to the tree. You can attach the node back to the tree if you want). queue_free() marks the node for deletion, removing it from memory after the current frame.