Hi,
I want to have a simple editor script that basically creates a camera, captures a screesnshot and destroys the camera after making the screenshot.
In editor script I can only use DestroyImmediat() to destroy the Camera.
But it seems like DestroyImmediat() is destroying the Camera before the screenshot is captured.
Is there a simple solution for this?
public class TestDB_acces : MonoBehaviour {
[MenuItem(“Add-On/TestDB_acces #&d”)]
public static void Change()
{
GameObject camera;
camera = new GameObject(“Camera”);
camera.AddComponent();
camera.transform.position = new Vector3(0, 0, 0);
Hi,
thx for the quick response
I can’t use Destroy() in a editor script
Having it there all the time might be the second choice of doing it.
I’m student and writing this tool for my school, so other people that are not familiar with unity will use it, I thought it might be confusing for them to have a second camera hanging around.
Yeah, sorry. Only half read your post You can’t use Destroy in the editor.
I just quickly tried your code and it didn’t take a screenshot for me even when the object wasn’t destroyed. I’ve never tried taking a screenshot in the editor. I’ll have to have a think on it.
Also this is mentioned in the docs which may explain why it is not capturing:
Note: Screenshots can be made from the Editor as described above. In this case only the Game view can be captured. If the Scene view is selected any screenshot will not be written. Switching to the Game view will cause the most recent captured image to be written. See EditorWindow for how an editor-based capture window can be created. If the Game view is current and the Editor button is clicked multiple times the first generated screenshot will be written. Application.CaptureScreenshot is a Game specific function.
Yes thats the problem it takes it from the main camera because the camera you created gets destroyed before the screenshot is taken, well that’s my theory haha. If you delete the line DestroyImmediat(camera), it takes it from the camera you created.