Is there any way to bake function pointers on blobs or entities (or systems?)
I`m creating a system to bake a state machine (as a blob asset) out of a xNode graph but having problems baking user create functions to execute on a specific state.
I have solved baking prefabs as a dynamic buffer element on entity (and index on blob) but for functions there is no way
Associate each function pointer with a type, then bake the stable hash of that type. Then at runtime, load up all associated types and build a hashmap of stable hash to function pointer.
I have types that implement an interface, and I have source generators generate the code that produces the function pointers. Then at startup I find all the types implementing the interface via reflection and get their function pointers.
The source generator for me is just to remove a bunch of boilerplate. All it does is set up the static Burst-compiled method and the thing that generates the function pointer.
But really, if your graph is composed of nodes, then each node type would have a function pointer. The full list of node types in your project would only change when you make code changes. If all you did was rearrange the nodes or changed parameters, then you could simply rebake that.
Also I just noticed line 181 is wrong. That’s supposed to be header.header.scriptType. Basically, I have runtime IDs during baking, and runtime IDs at runtime, which can be different. And then I store the mapping of the bake-time IDs to hashes in a blob asset, and then get the new runtime IDs. The runtime IDs can then be used to index function pointer tables, which I build at startup:
That’s probably possible. I certainly have options if this ends up leaving a dent on the profiler. I opted for API ease-of-use in my initial implementation.
No. But the error message changed in Burst 1.8.19, and while still incredibly cryptic, I was able to figure out what in particular Burst didn’t like. Turns out that if you have a default interface method that calls into an interface method implemented by a derived interface or struct, Burst forgets the type information of the derived type, causing null reference exceptions. Similarly, Burst will also forget the generic type arguments for a generic interface with a default interface method.
While I had to sacrifice a couple of minor features, I have the system working now in Burst.