- Home /
How can I delete the Main Camera using a script?
So I'm attempting to create a wizard that will create a totally empty scene before it loads a default scene (which already contains a modified main camera) using EditorApplication.OpenSceneAdditive(defaultMap);
My script (provided below) generates the following error:
Can't remove component.
Can't remove Camera because GUILayer, FlareLayer depends on it
So how can I go about deleting / removing the dependancy between the GUILayer and FlareLayer? Will these things come along with my default scene?
using UnityEngine; using UnityEditor; using System.Collections;
public class EmptySceneWizard : ScriptableWizard {
[MenuItem ("Wizards/Empty Scene Wizard")]
static void DoWizard() {
ScriptableWizard.DisplayWizard("Empty Scene Wizard", typeof(EmptySceneWizard));
}
void OnWizardCreate() {
EditorApplication.NewScene();
DestroyImmediate(Camera.main);
}
}
$$anonymous$$y testing today indicates that a camera loaded with OpenSceneAdditive will not become the main camera, even if it is tagged as such and enabled. Have you had the same issue?
Answer by Eric5h5 · Dec 09, 2010 at 11:49 PM
Destroy the camera's GameObject, not just the camera component.
perfect! thank you!
DestroyImmediate(Camera.main.gameObject);
Your answer
![](https://koobas.hobune.stream/wayback/20220613090433im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Problem with click to display information 1 Answer
How To Stop Destroyer From Destroying? 2 Answers
Save game objects to new scene 0 Answers
How to load a scene on collision 1 Answer