Search Unity

Storing Texture across Scenes

Discussion in 'Scripting' started by denali95, Sep 24, 2017.

  1. denali95

    denali95

    Joined:
    Nov 6, 2016
    Posts:
    78
    I'd like to set a texture in one scene, and hold onto it so that I can access it again in another scene. How can I do this?
     
  2. Invertex

    Invertex

    Joined:
    Nov 7, 2013
    Posts:
    1,546
    A couple ways.

    1.) You could have a static class that holds your references, it will retain its references for the life of the executable.

    2.) You can have the script that holds the texture reference have this be called on it:
    https://docs.unity3d.com/ScriptReference/Object.DontDestroyOnLoad.html

    This way the object won't be destroyed between scene loads.
     
    denali95 likes this.