ScriptableObject to Job

Hi there

I’m slowly moving my code to job system (Without ECS) and currently i need advise on how to make my configuration data built using scriptableobject to job system ready.

For example, do i on runtime take data from scriptableobject’s List to my Job’s NativeList
OR
Can i directly save NativeList inside scriptableobject and use it?

Or is there some better way

Thanks

You can’t serialize native arrays unfortunately. Your first option is kind of all there is right now for transferring data to jobs. A nice way of writing modular code in Unity without ECS but also nicely supporting the job system would be to use (shameless plug) Scriptable Framework:

Github: GitHub - pablothedolphin/Scriptable-Framework: A Unity Framework for modular app creation based on ScriptableObject architecture, data oriented design and event driven programming to help programmers and designers adhere to the 5 SOLID programming principals.
Docs: Scriptable Framework - Manual

It’s based on scriptable object architecture and offers convenient scriptable object types for lists of floats and is easily extensible.

What makes this suitable to your problem is that there are already methods to convert the collections into native arrays for you and you can even initialise the objects with custom default data when you hit play. There’s also a scriptable mathematics package for added collections that support float3 if you needed that.

So you can basically have a set up similar to ECS using scriptable objects without the need to convert your whole game.

1 Like

Do you need to change your configuration data at runtime? If not then converting that into a Blob Asset would be a good idea, and they are very easy and fast to read from in jobs.

If you need to change data at runtime, then a component to hold the data stored on a singleton entity would probably do what you need.

In both cases you could use the conversion pipeline to convert your scriptable object into a blob or component.

1 Like

Thank you guys for your detailed replies.

I can see that Scriptable Framework is a good choice to simplify complex use cases. So thanks for that @JakHussain

@siggigg In my case configuration data will not change, and as its a simple case so Blob Asset seems a good fit. Can i use it for JOBS without getting into ECS. Secondly is there any tutorial/use case to follow it as i couldnt find anything on google?

Unfortunately there is not a lot of documentation on it yet. The best resources are probably the DOTS game conversion talk from Unite Copenhagen and the tests for the classes. You can also look at the new Unity ECS Physics package, they use it for the collider information for example.

However I haven’t tried using blobs without ECS, but I can imagine you could do something like setting up a singleton entity and access that from where you declare the job and the pass the blob data into the job.

1 Like