Is there something like a node ID which is specific to that node and will be the same no matter how often I execute the game? That would be super useful for saving and loading games.

3 points

What is your use case? That would help narrow down a good solution. Node path could likely work. You could also add a uuid or similar (there’s an extension that provides a uuid implementation). Might be hacky, but you could tap into this and see if it suits your needs https://docs.godotengine.org/en/stable/classes/class_resourceuid.html

permalink
report
reply
1 point

I want to use this unique value as a key for a dictionary, which will have some data in it (positions, rotations and some custom values)

permalink
report
parent
reply
1 point

Is there a reason you don’t want to serialize that data with the nodes that use them? Are those values intended to change when the entity isn’t loaded into a scene (like a background simulation or something)?

Seems like adding your own uuid or tapping into the ResourceUid class might be your best option

permalink
report
parent
reply
1 point

I don’t really know what you mean by serializing the data. I am using a custom data type for saving all the relevant stuff, in case that is what you mean. That date type stores only the position and rotation and optionally some other stuff too.

permalink
report
parent
reply
2 points

Node paths are unique and stay consistent across restarts, although I don’t know if that’s exactly what you’re asking for.

permalink
report
reply
1 point

This works really well when you have one large world on which you want to save many different objects, but I would like to have a node unique ID which is unique across the entire project. Otherwise though, a really good call, thank you!

permalink
report
parent
reply
1 point
*

scene name + node path

permalink
report
parent
reply
1 point

I’ve thought about this problem creating a system to save game state. The issue with assigning a UUID works until you have dynamic scenes added to the game at runtime. The nodes in those scenes will all have the same UUID. In the end I ended up just using the paths and saving the fact that the scene that data is being saved for is dynamic. Then the system sees this and re-instances the scene and adds it back to the tree. (A slight adjustment to the path must be made as Godot will create nodes with the at (@) symbol in them, but you can’t do that yourself.)

You can see this in action at my demo repo on github.

permalink
report
reply

Godot

!godot@programming.dev

Create post

Welcome to the programming.dev Godot community!

This is a place where you can discuss about anything relating to the Godot game engine. Feel free to ask questions, post tutorials, show off your godot game, etc.

Make sure to follow the Godot CoC while chatting

We have a matrix room that can be used for chatting with other members of the community here

Links

Other Communities

Rules

  • Posts need to be in english
  • Posts with explicit content must be tagged with nsfw
  • We do not condone harassment inside the community as well as trolling or equivalent behaviour
  • Do not post illegal materials or post things encouraging actions such as pirating games

We have a four strike system in this community where you get warned the first time you break a rule, then given a week ban, then given a year ban, then a permanent ban. Certain actions may bypass this and go straight to permanent ban if severe enough and done with malicious intent

Wormhole

!roguelikedev@programming.dev

Credits

  • The icon is a modified version of the official godot engine logo (changing the colors to a gradient and black background)
  • The banner is from Godot Design

Community stats

  • 767

    Monthly active users

  • 702

    Posts

  • 2.8K

    Comments