#Custom Resource not able to reference another Custom Resource

1 messages · Page 1 of 1 (latest)

sleek shell
#

Hey, I have a Problem with custom Resources and after searching around I only found this post, which explains exactly my Problem: https://forum.godotengine.org/t/customresource-not-able-to-save-another-customresource-that-also-has-it-saved-as-a-variable/69650
My source code: https://github.com/Arbee4ever/Train-Game/tree/rewrite
Example Savefile with broken references to custom Resource (all null variables): https://github.com/Arbee4ever/Train-Game/blob/rewrite/network.tres

GitHub

Contribute to Arbee4ever/Train-Game development by creating an account on GitHub.

GitHub

Contribute to Arbee4ever/Train-Game development by creating an account on GitHub.

sleek hornet
#

The godot resource system doesn't like circular references in general. I don't actually know the best practice to get around that though

sleek shell
#

I mean I could make it id based, but that would mean I'd have to ask the TrackNetwork class everytime what Resource this id was again, which seems quite inefficient

vital pike
# sleek shell Hey, I have a Problem with custom Resources and after searching around I only fo...

So I'm not sure about your code/usage, but I wonder if you can you rewrite your "network" into a DAG (https://en.wikipedia.org/wiki/Directed_acyclic_graph).

Basically, getting rid of the loops.

One way could be to compare id's, and only let the lower one link to the higher one.
So instead of this:

1 -> 2
2 -> 1```
Since 1 is lower than 2, only store this link:
```1 -> 2```
If your network always has bi-directional links, you know that `1 -> 2` implies `2 -> 1`. But you've only stored half of that and prevented loops (with saving at least).
sleek shell
#

Hmmm.. that could work

vital pike
# sleek shell Hmmm.. that could work

A potential alternative could be a "NetworkManager".
Just like when using a SceneManager to prevent preload() loops, a manager could be doing the same here?

Instead of this:

1 -> 2
2 -> 1

It would be more like this:

NetworkManager -> 1
NetworkManager -> 2
NetworkManager -> link(1,2)

Or maybe even without the -> 1 and -> 2? Just the link().