Giter VIP home page Giter VIP logo

Comments (6)

soraphis avatar soraphis commented on June 7, 2024

could be implemented like this: soraphis@f95307c

from unity-atoms.

AdamRamberg avatar AdamRamberg commented on June 7, 2024

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.

soraphis avatar soraphis commented on June 7, 2024

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.

AdamRamberg avatar AdamRamberg commented on June 7, 2024

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.

soraphis avatar soraphis commented on June 7, 2024

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.

AdamRamberg avatar AdamRamberg commented on June 7, 2024

Implemented in 06eab90 and fixes in ed57421

from unity-atoms.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.