#Fetching and Processing Dynamic Arrays from ISystem

1 messages · Page 1 of 1 (latest)

manic hazel
#

I have a large JSON object that I'm translating to an array within a singleton in my application. This array will be frequently updated, possibly changing almost every frame. I need to fetch this array from my ISystem, iterate through its elements, and apply a function to each element. What's the best approach to fetch the array from ISystem without encountering problems?

I don't really know the best tag to put 😦

hard crow
#

the “array within the singleton” should be a dynamic buffer singleton instead

manic hazel
#

Oh ok I will look into that thx 🙂
I was doing a different approach modifying the value inside authoring and then get it from the system.

hard crow
#

If you are talking about something that changes every frame, you should know that authoring only runs in the editor, not in a build or at runtime. The result of authoring is what gets serialized. The one exception is that authoring will sort of run at runtime if you have a subscene open while in playmode... but this is a lie and Unity probably shouldn't allow it since it confuses people.

manic hazel
#

Oh ok I didn't know that

#

Thank you
So now I have other question I have a NativeArray that I wanted to save it and access it from the system. How should I do that. It's something permanent that as a NativeArray of Entities I initialize it fill it with values then it doesnt change again how should I implement that?

hard crow
#

Are you generating this array at runtime or during authoring?

manic hazel
#

during runtime

#

I do it in the first interation of the OnUpdate inside of the Isystem because I need to "spawn" various entities so after if I wanted to make it faster I would do it with jobs because it needs to spawn more than 2 million entities

hard crow
#

why do you need to store 2 million entities in an array? Can you just tag them with a component?

manic hazel
#

Because I need to acess more or less 10k of them everyframe and change their texture.
So if I had them already stored it would cost less to acess them

hard crow
#

I feel like you're trying to reinvent ECS inside ECS 😄

#

the ECS archetype system does that for you

manic hazel
#

Yhea maybe Im overcomplicating xd

manic hazel
hard crow
#

when you define an entity query, the framework is making a unique table (called an archetype) of that query which makes the query very fast to run... in the same exact way that creating your own list would do. It's because of these unique tables that "structural changes" are expensive as one structural change can require updating multiple tables

manic hazel
#

Hmm okk But like I wont change the reference of the entity to the memory I will just change a component inside of it so it should be fine.
But the problem is the query doesnt give them in order and I needed to get the order of them.
Because i wont change random 10k entities i will have the x,y of the ones I need to change

#

and with the query it will be difficult to achieve that no?

#

or theres some way to get them "ordered"

hard crow