Search Unity

Feature Request Scenewide Variables

Discussion in 'Editor & General Support' started by arrowmaster1252, May 24, 2022.

?

Do you think this is a good idea?

  1. Yes

    100.0%
  2. No

    0 vote(s)
    0.0%
  1. arrowmaster1252

    arrowmaster1252

    Joined:
    May 7, 2020
    Posts:
    1
    I don't know if this is already a thing, I tried googling it and couldn't find it. If it is I would love to know what it is called and get a link to the documentation.

    Basically it is variables that is specific to the scenes. You can access it like a static variable (using a class or whatever for that), but it can contain scene specific references. I often find myself with a class that needs to have a reference too it in most other scripts I make, but with this that could be SceneVariables.ThatClassINeed instead of an independent variable on each script that if it needs to be changed will be a hassle.

    I know this is similar to simpletons, but think this would be a nicer way to allow people to achieve stuff like that.

    Thank you for reading.
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,911
    There's nothing built in for this but it's easily achievable with the tools at hand. You could simply make a
    Code (CSharp):
    1. static Dictionary<Scene, MyVariableholder>
    - thus having scenewide variables easily accessible. You'd have to of course do a little bookkeeping, but it's nothing crazy.