Currently there is no sample of loading and using dynamic dataset (csv, scriptableobject) by Entity Spawners at runtime. Everything is already set at the authoring phase on prefabs or subscenes. But being able to use dynamic dataset at runtime is a very important part of many products. Will there be a sample demonstrating how to do this?
#Samples of loading and using dynamic dataset to use in entity spawners
1 messages · Page 1 of 1 (latest)
I mean there's nothing stopping one from loading a csv at runtime, and then doing a bunch of SetComponent etc 
I mean I need an example showing how to do this. Currently I'm trying to understand how to make ECS works with other non-ECS systems. And I'm feeling a bit indirectional about this part. Such as: how do I connect this csv dataset to the spawners?
I load a memory mapped file on runtime to read misc data and I pretty much do what Dani said. I just do a bunch of SetComponent calls and such after I finish reading the memory mapped file. This happens once a singleton entity exists so OnStartRunning.
Another option is to build immutable BlobAssets from your data (whether it be in ScriptableObjects, csvs, runtime generation, etc) and reference those in your systems.
BlobBuilder is available in the Editor, during baking, and at runtime: https://docs.unity3d.com/Packages/com.unity.entities@1.0/api/Unity.Entities.BlobBuilder.html
Thanks, I will try to connect the dots then.
I understand I have to use SetComponent to set values to entities. But I don't really understand how SetComponent gets the data from the dataset. Where does this procedure happen? Could you please put a snippet here? Much appreciated!
Well here's a really basic example of what I had done. SetComponentData from EntityManager isn't reading any data. You're having a separate method/function that will read the data and provide it to the EntityManager or an EntityCommandBuffer if you choose to use this in a job.
// Some pseudocode of the general idea.
void OnStartRunning() {
using var mmf = MemoryMappedFile.Open(...);
using var accessor = mmf.CreateViewAccessor(...);
// You can read arrays or other datatypes supported, but if you're doing arrays
// they allocate in managed memory
// You can also get a pointer to the memory mapped file if you're comfortable working with them
// for Bursted Jobs.
int value = accessor.ReadInt(...);
var entity = EntityManager.CreateEntity();
EntityManager.SetComponentData(entity, new SomeComponent { Value = value });
}