- Home /
Render to texture without a display.
I have a game that currently runs as an exe on a windows box. My game currently opens a socket to listen for requests, it then takes these requests, loads an asset, takes a screen shot of it using a RenderTexture, then saves the image. This all works great when I run my game in normal fashion, i.e., running it as a windowed app. What I would like to do is have my game run in the background as a windows service so that it is not accidentally closed and is auto restarted when the box is rebooted.
I've installed my exe as a windows service using the "sc create" command. When I start the service I get the following error in the unity standalone log file:
IndexOutOfRangeException: Array index is out of range. at UnityEngine.Display.RecreateDisplayList (System.IntPtr[] nativeDisplay) [0x00030] in C:\BuildAgent\work\d63dfc6385190b60\artifacts\StandalonePlayerGenerated\UnityEngineDisplay.cs:95 (Filename: C Line: 0)
desktop: 1024x768 60Hz; virtual: 1024x768 at 0,0 Switching to resolution 1024x768 failed, trying lower one All resolution switches have failed Screen: DX11 could not switch resolution (1024x768 fs=0 hz=0)
I believe this is due to the fact that when my game runs as a service there is no display window. I would prefer to not have a window so it doesn't get closed by accident, and since there is no user interaction, it just gets in the way.
Is it possible to render to an image without the game window open?
I'm using Unity Pro 4.6.
Have you ever got this working? I am running into same issue and I am interested if Unity can be used to render textures from background windows service.
Did you find a solution? i am looking for the exact same thing.
I never found a solution. I run my app on a remote server and have to remote desktop into it and restart the app whenever the box is rebooted.
I actually found a solution after I posted here.
Do you run the standalone player in batchmode? (without display and user input) Running a standalone player in batchmode (cmdline): mystandaloneplayer.exe -batchmode
In order to render to rendertexture in batchmode, I found I had to manually render using mycamera.Render(); (with rendertexture as targettexture on the camera).
Are you sure you're app is using the GPU? I seem to remember doing something like this and the problem I had was the app wasn't using the GPU for rendering and ins$$anonymous$$d it was using a software renderer. Check the log file after you app is started and make sure you see something like the following:
Version: Direct3D 11.0 [level 11.0]
Renderer: A$$anonymous$$D RADEON HD 6450 (ID=0x6779)
I think you're right. Speed is not an issue for me though, as I am not running a realtime app (I'm simply generating thousands of images for use in something else.)
Answer by Paulius-Liekis · Jan 28, 2015 at 08:43 PM
Check this out:
http://docs.unity3d.com/Manual/CommandLineArguments.html
-batchmode
might do the trick.
I tried this, the images that get created are just grey images. When running batchmode, Unity doesn't initialize the graphics pipeline at all. I believe batchmode is for running things like networking servers or build servers. I could be wrong though.
If I look at the output when running in batchmode I see something like this:
Initialize engine version: 4.6.1f1 (d1db7a1b5196) Forcing GfxDevice: 4 NullGfxDevice:
Version: NULL 1.0 [1.0]
Renderer: Null Device
Vendor: Unity Technologies
Compared to a normal start up, I see this:
Initialize engine version: 4.6.1f1 (d1db7a1b5196) GfxDevice: creating device client; threaded=1 Direct3D:
Version: Direct3D 11.0 [level 11.0]
Renderer: A$$anonymous$$D RADEON HD 6450 (ID=0x6779)
Vendor: ATI
VRA$$anonymous$$: 1010 $$anonymous$$B
Documentation on -nographics implies that -batchmode should have graphics initialized.
You could also try forcing gl/dx, maybe that would help.
I too thought the -nographics would imply graphics, but when I run my app in batchmode my images are empty. When I force open gl I get a really long and weird stack trace that ends with "crash!!"...kind of funny.
You could try using Editor (in batch mode) to generate these screenshots. $$anonymous$$aybe it works better than standalone build...
Your answer
Follow this Question
Related Questions
Render a Unity game as a texture in another Unity game on Windows 0 Answers
How to use a Render Textures Native Pointer in another process 0 Answers
Check If Service Is Running C#? 1 Answer
How can I get the RenderTexture OpenGL texture ID? 4 Answers
Command line to install Unity's cache server as a service on windows 1 Answer