Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Event for when RenderTexture is lost

Discussion in 'General Graphics' started by allenwp, Jun 21, 2016.

  1. allenwp

    allenwp

    Joined:
    Sep 4, 2013
    Posts:
    46
    Hi there,

    I'd like to save a RenderTexture before it becomes lost (due to "loading a new level, system going to a screensaver mode, in and out of fullscreen and so on"). Performing a Texture2D.ReadPixels(...) call every frame sounds like a bad idea, as I expect this is a costly call (I believe reading pixels from a GPU memory is typically slow). Is there a way I can subscribe to an event that is sent when the RenderTexture might be lost, so I can save it and restore it later?

    My situation is the following:

    I'm working on a platform that has a fair bit of memory but very little processing power. I'd like the player to be able to draw on the screen. Their drawings are mostly throw away and the player won't have any way of saving them, but they will need to be stable through a session of the game, regardless of whether the system enters a sleep state or whatever else. Simply rendering to a RenderTexture and never clearing is the fastest way to do this, but also seems the most scary if I have no way of ensuring the contents of the RenderTexture won't be lost...

    Thanks,
    Allen
     
    kittycon likes this.
  2. kittycon

    kittycon

    Joined:
    Jan 12, 2016
    Posts:
    15
    I have same problem, did you find the solution?
     
  3. allenwp

    allenwp

    Joined:
    Sep 4, 2013
    Posts:
    46
    I forgot about this! We ended up ditching the feature because it took away from the fun of the game.

    If I remember correctly... I was planning to create the texture data on both the CPU and GPU side so that the GPU memory could be reloaded with data that was kept on the CPU side. I was considering storing the line segments that made up the texture I was creating... But I think the best approach for my situation was to create identical texture data on the CPU side as it was created...