behavior3 / behavior3editor

An awesome online visual editor for Behavior3 (Behavior Trees Visual Editor)
MIT License
643 stars 264 forks source link

Unable to open project with nested trees #5

Open closeratio opened 9 years ago

closeratio commented 9 years ago

If I have a project where a tree references another tree that is below it in the list on the left of the editor, I save the project, and then attempt to reopen it, the editor fails with an error message.

After taking a bit of a look at the source, this appears to be because the trees in the serialised JSON are stored in an array, and if a tree refers to a nested tree which exists after it in said array, it won't have added it within the NodeManager, and hence will fail.

I would either suggest changing the JSON format so that the trees are stored as key-value pairs (much like the nodes), or having an additional processing phase before attempting to load the tree, so that the node manager is aware of all the nodes that exist within the project file. The latter approach wouldn't invalidate existing projects files, and is probably the preferred one from my point of view.

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/26612759-unable-to-open-project-with-nested-trees?utm_campaign=plugin&utm_content=tracker%2F18331319&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F18331319&utm_medium=issues&utm_source=github).
renatopp commented 9 years ago

Thanks for reporting this. The multiple trees feature is turning out to be a real pain to implement, not just in the editor but also in the client libraries.

In order to have a more descriptive issue, I'm going to create another thread about how to handle multiple trees (see #8) and keep this one open as a current bug. I would like to fix this bug together with the changes on the multiple trees feature.