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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question Is there any way to access Unity SessionState at runtime?

Discussion in 'Editor & General Support' started by sankethhegde, Jun 22, 2023.

  1. sankethhegde

    sankethhegde

    Joined:
    Jun 9, 2023
    Posts:
    6
    I am storing some data in SessionState via an editor window script. Is it possible to retrieve this data at runtime in the editor during playmode? I don't have access to SessionState or any of the UnityEditor API during runtime, which makes sense, but I'm wondering if there's another way.

    Thanks.
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,752
    Of course, using the same SessionState API
    You can use the UnityEditor API in editor play mode no problem. It's when you make a build that you can't use it.

    If you are intending to access the editor session state in a build, that's obviously not possible.
     
  3. sankethhegde

    sankethhegde

    Joined:
    Jun 9, 2023
    Posts:
    6
    Thanks for the reply. My problem is that I'm trying to access SessionState in package code that is built to a runtime DLL. I realized that this is why I don't have access to the UnityEditor API and this is also why I can't use the
    #if UNITY_EDITOR
    preprocessor directive.

    Do you know of any way I can get around this?
     
  4. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,752
    You can set the assembly to be built in the editor (which will allow access to editor apis) in the assembly definition inspector in your package.
     
  5. sankethhegde

    sankethhegde

    Joined:
    Jun 9, 2023
    Posts:
    6
    I do have Editor checked in the runtime .asmdef (see attached screenshot) but for some reason, I only have access to
    UnityEditor.Experimental
    . Trying to access SessionState results in
    The type or namespace name 'SessionState' does not exist in the namespace 'UnityEditor' (are you missing an assembly reference?)
     

    Attached Files: