Comments (6)
could be implemented like this: soraphis@f95307c
from unity-atoms.
This is a great feature and something that I've been thinking about / toying around with myself. However, I think there are different use cases, sometimes you want the value to persist between scenes and plays and sometimes you want it to be reseted to an initial value. Therefore, I propose that the ScriptableObjectVariable should also contain a ScriptableObjectVariableBase called initalValue (this will need to be part of the generic signature in order to be serialized properly). If the constant (ScriptableObjectVariableBase) is set we set in OnAfterDeserialize, otherwise we don't. Would gladly accept a pull request (but I might also try to implement this right away - so check if it has already been implemented before doing a pull request).
Side note: when you want to reset something at the start of a scene you can use OnStartHook combined with SetVariable.
from unity-atoms.
sometimes you want the value to persist between scenes and plays
this is a dangerous thing! while you might want it for in-editor features this will never happen in builds. because of that I highly recommend implementing a reset system.
(also: in-editor features will probably not use unity-atoms)
Therefore, I propose that the ScriptableObjectVariable should also contain a ScriptableObjectVariableBase called initalValue (this will need to be part of the generic signature in order to be serialized properly)
I'd argue against that, because: you'd need for nearly all variables an additional variable for resets. this reset variable would have its own description fields, old values, events, and so on
while all you actually want is: a boolean flag whether or not you wanna reset, with a default on true. (because really, I can't imagine a case where you want to store something inbetween editor sessions)
Side note: when you want to reset something at the start of a scene you can use OnStartHook combined with SetVariable.
which will introduce WAY MORE assets than i actually need (it doubles the amount).
in the game we made the other week, we had around ~10!? unity-atom variables. that would be 20 + the OnStartHook.
from unity-atoms.
while you might want it for in-editor features this will never happen in builds.
Risking sounding like a noob. I have been looking into this before, but I remembered that it actually was saved between plays in build. Just tried it, and yes you are right. Thanks!
I'd argue against that, because: you'd need for nearly all variables an additional variable for resets. this reset variable would have its own description fields, old values, events, and so on
So because of the above reasoning I agree with you 👍
Maybe it would be great though to be able to persist state between plays, by serializing to json / xml for example. What do you think? Should I create a new issue for that?
while all you actually want is: a boolean flag whether or not you wanna reset, with a default on true. (because really, I can't imagine a case where you want to store something inbetween editor sessions)
On a second note, yes a boolean would probably be much easier and will introduce way less asset files (a good thing).
Question, do you know if OnAfterDeserialize
and OnBeforeSerialize
are called when switching between scenes? Is it different when running in the editor vs in an actual build?
from unity-atoms.
Maybe it would be great though to be able to persist state between plays, by serializing to json / xml for example. What do you think? Should I create a new issue for that?
for me, that is the job of a savegame system. In the game project I worked the other week i also have a savegame system. I read values from atom-variables and on load i feed them back in.
Serializable variables - for me - are mainly a way to provide vales across multiple scenes (or across multiple prefabs).
Question, do you know if OnAfterDeserialize and OnBeforeSerialize are called when switching between scenes? Is it different when running in the editor vs in an actual build?
In the editor: they are called when entering playmode. they are not called for scene changes (neither playmode nor edit mode). they are called when unity recompiles and maybe on a few other ocassions.
in the build: "OnAfterDeserialize" is called once, when the game starts.
(i just tested that with a debugger)
In my project I'm currently using my fork of unity atoms, and I have not found a problem with OnAfterDeserialize yet. and it reduced "initialization code" - code lines where i just made sure that on game start the atom-variables have a specific value.
from unity-atoms.
Implemented in 06eab90 and fixes in ed57421
from unity-atoms.
Related Issues (20)
- [FEATURE] Upgrading Documentation to Docusaurus 2.x and adding a search plugin
- [BUG] NullReferenceException in HandlePlayModeStateChange HOT 1
- [BUG] AtomValueList keeps runtime modifications HOT 1
- [BUG] AtomValueList not compatible with disabled domain reload HOT 1
- [FEATURE] Improve Inspector legibility
- [BUG] FiniteStateMachine not firing events anymore HOT 2
- A number of issues with AtomLists/AtomCollections HOT 2
- [FEATURE] More public get-properties for fields HOT 2
- [QUESTION] Subpackages documentation HOT 2
- [FEATURE] Variable Resetter shouldn't trigger due to script hot reload
- [FEATURE] Clear "AtomList" and "AtomCollection" OnEnable
- [FEATURE] SceneField for Addressable Scenes
- [BUG] StackTraces allocate garbage when DebugMode = false HOT 1
- [BUG] QuaternionReferenceDrawer Rendering issue HOT 1
- [BUG] CustomStruct Reference Drawer Rendering issue
- [FEATURE] AtomTags - Update TagInstances in Editor
- [FEATURE] Auto drag and drop atom references through inspector without the need to manually switch usage type
- [FEATURE] AtomBaseEventReference to have `Raise` methods inside
- [FEATURE] VFX PropertyBinder HOT 1
- [BUG] Recompiling during play mode resets all variables HOT 10
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from unity-atoms.