Can we get an API to retrieve a scenenode by GUID?

It’d sure be great if we could retrieve a scenenode by GUID.

E.g., if you want to store a reference to another node in a node’s pluginData, the only JSON-safe method would be by GUID (a string).

It would be nice to have a native, fast way of doing this. But in the meanwhile, here’s something I use:

  let flatten = t => {
    let rec aux = (acc, t) => {
      let x = [t, ...acc];
      let xs = children(t) |> toList |> List.map(aux([])) |> List.concat;
      List.concat([x, xs]);
    };
    aux([], t);
  };

  let findByIds = (t, ids) => {
    let idExists = id => Belt.Array.some(ids, x => id == x);
    flatten(t) |> List.filter(t => idExists(guid(t)));
  };

This code is in Reason/OCaml – it flattens the root node into a list of nodes, and then does a linear search by guid. This is a quick & dirty approach – a more efficient way would be to do the search while traversing the tree.

Sure, one could always do a tree search, but that’s brute-forcing it, and it would be practically impossible for a large node scene with many lookups.

@stevekwak, @peterflynn ^^^