Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question It's good praxis to store temporal variables in a scriptable object?

Discussion in 'Scripting' started by carcasanchez, Oct 22, 2021.

  1. carcasanchez

    carcasanchez

    Joined:
    Jul 15, 2018
    Posts:
    177
    I am using scriptable objects with a simple function inside that gets called every frame, but there's a variable that needs to be stored among frames. Is a private variable that doesn't get read outside the scriptable object. As far as I know, scriptable objects are only meant to store and read data. I have not run into issues by now, but what could be possibly happen? Is there any issue by doing this?
     
  2. exiguous

    exiguous

    Joined:
    Nov 21, 2010
    Posts:
    1,749
    In the end scriptable objects are "normal" classes with some unity stuff. So it's not "forbidden" to use it like this. Just be aware that the private member will not get serialized automatically but from your description it seems that's not required anyway. And when you clone/instantiate it how the initial value set?
     
    Joe-Censored likes this.
  3. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    If I remember correctly, Praxis exploded due to overmining and insufficient safety precautions.

    :p
     
    exiguous likes this.
  4. exiguous

    exiguous

    Joined:
    Nov 21, 2010
    Posts:
    1,749
    Huh? I thought it was a covert federation sabotage act with help of the romulans. You know, the films are distorting the truth? ;)
     
    Joe-Censored likes this.
  5. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    I thought I'd stick with the mainstream narrative rather than have this conspiracy theory debate. :)
     
    exiguous and JeffDUnity3D like this.
  6. carcasanchez

    carcasanchez

    Joined:
    Jul 15, 2018
    Posts:
    177
    I have moved the behaviour from scriptable objects to mono behaviour, as it was getting to messy to have in a separated script. So i just use Scriptable as data containers
     
    Joe-Censored likes this.