#Save precomputed data to project

1 messages · Page 1 of 1 (latest)

lament granite
#

I have a dictionary that i would like to store for later use in the built project.
Ive thought about using a scriptable object, but that is only editor mode persistance from what i could see. Do i just write some json file into the resources folder and read from this, or is there some simpler/better method :)
is Application.dataPath valid for this (or some variant of this)?

thanks in advance

stray lava
#

Your question is missing context! What are you trying to do?

Scriptable objects are resources like any other that can be read in the game, do you mean you want to modify it at runtime? In that case the resources folder won't work because you're not supposed to write to that at runtime.

If you're talking about ECS, you could store a reference to a scriptable object in a managed component, or using UnityObjectRef<T>. Alternatively you can bake the data manually into a regular component or blob asset.

Note that by default unity does not serialize dictionaries.

Application.dataPath is the folder to your executable / name_Data , it's supposed to be read-only, but you can definitely store things in that in a post-build script. If you want to store things like save data, you should be looking at Application.persistentDataPath.

lament granite
#

i want something that can write data in runtime in the unity editor that can be used for future runs of the game in both the editor and in build

#

would Application.dataPath be suitable for this task
seems like it would based on what you said

if so then how do i read from that path in build? using the File class ?

desert cave
#

Just to double-check, does this actually have to do with Entities baking or content management?
Because nothing so far indicates it should be in this forum

stray lava
lament granite
lament granite
# stray lava no, you probably want `Application.persistentDataPath` any of the C# classes tha...

is there a place i should be asking my questions in the future. i didn’t notice a forum for it

you mentioned that the persistantDataPath should be used instead, but above you said dataPath is read only in build which is what i needed. i wanted write in editor, and read in build. it’s not save data that i want to store, its data that im recomputing in the editor and saving it for later in the built game

stray lava
#

i want something that can write data in runtime
Then maybe you didn't say what you meant? I interpreted this as wanting to write data at runtime.

lament granite
#

you cut the next 3 words which clearly explain the rest

#

… in runtime IN THE EDITOR

stray lava
#

yes, I read that, it just wasn't clear

lament granite
#

also the description of the post mentions that too :P

stray lava
#

If you write to Application.dataPath in the editor, it will not put that data in the build, you need to handle this differently. If you make it a ScriptableObject it will be included in the build automatically, otherwise you may need some to run kind of post-build

lament granite
stray lava
lament granite
#

i think i’m using them wrong

stray lava
#

you probably have to mark it as dirty using EditorUtility or something, they won't be saved automatically if you write to them in memory

lament granite
#

can you give me an example using a simple bool or something

i really don’t know what im doing wrong

#

if you feel like it :0

stray lava
lament granite
#

can scriptable objects store a dictionary, or do i have to split it into 2 arrays