#Samples of loading and using dynamic dataset to use in entity spawners

1 messages · Page 1 of 1 (latest)

karmic plinth
#

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?

formal lynx
#

I mean there's nothing stopping one from loading a csv at runtime, and then doing a bunch of SetComponent etc think

karmic plinth
#

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?

flat wind
#

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.

weak arrow
karmic plinth
karmic plinth
flat wind
#

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 });
}