- Home /
Can i load a scene with no Camera
Can I load a scene even if it doesn't have a Camera in it if so how.
Currently I am trying to Have a camera persist throught the scenes (I'm writing an AR project). The camera loads in the beginning which is what I want. Once the camera is loaded I turn it to
transform.gameObject.active = false
Then in a later scene I have an empty object which is supposed to call
camera = GameObject.Find("ARCamera");
//check if not null
camera.active = true;
The problem is It doesn't look like my GetCamera script is being run. Nor are any other scripts in that scene. So does that mean I need to make a hack where I have a camera already there and find another one then switch or is there a clean way of loading a scene without a camera.
What are you trying to achieve by turning the camera off and then on when the scene loads? Is it to cleanly switch between scenes?
You could render a black polygon orthographic or move the camera inside a black box temporarily or a number of other ways to hide the actual transition from scene to scene.
I believe GameObject.Find() may only find items at the root of the hierarchy (i.e. not something parented to something else), in my experience (unless I was doing something wrong!) I have had to specify a hierarchical path like "/$$anonymous$$yParent/$$anonymous$$yChild/$$anonymous$$y_Item_I_Actually_Want".
Are you saying that scripts in your new scene are not being run? How are you loading the new scene? Presumably you remembered to add it to the build?
Some things to remember:
items that are disabled will not be found with GameObject.Find()
If you didn't use LoadLevelAdditive() or LoadLevelAdditiveAsync(), all objects NOT marked as DontDestroyOnLoad, will, erm be destroyed!
Probably a bit more detail will help...
I have 2 camera's loaded up in the first scene 1 is an Ar camera and the other is a regular camera. I wait for the Ar camera to finish loading its scripts and then turn it off so its scripts do not run when I do not have anything for them to run with. Then I wish to turn it back on in a later scene so it doesn't take 30 seconds to a $$anonymous$$ute to switch between scenes.
The problem is when I load the next scene $$anonymous$$y AssetHold Game object does not get run. I have two scripts attached to it and neither scripts start gets called.
No there are no errors in the console. It compiles with no problems, first it froze up the application, and now it loads the other camera but the scripts are messed up. i keep getting a nullpointer exception. I will post this quesiton on Vuforia's QCAR site. As i think it is more on their end than on unity's
Hmmm, if you're getting a NullPointerException then I am pretty sure this will be output in the console.
As soon as your script throws an exception, unless you handle it, then the script will ter$$anonymous$$ate, so the likely scenario here is that your script that finds the camera is running but throws an exception before it gets that far. Possible around the comment line // check if not null!
Answer by Meltdown · Jul 17, 2012 at 06:08 PM
Create an empty gameObject in your scene, and attach your script to that. To reference a Camera with the default tag of MainCamera use Camera.main To reference all cameras in a scene in an array use Camera.allCameras To find a specific camera us GameObject.Find("YourCamera").camera;
You can also create a camera as a prefab, and instantiate it in your scene from your initial script on your empty GameObject.
The only peice of this code that I can use is GameObject.Find("yourCamera") and i have already used it originally, Thanx though.
I cannot instantate a new prefab as the whole point of this is to load up the camera in the beginning of one scene ("start game" scene) and use it at a later scene so the loading does not stop my application.
@Ralgex what do you mean by "so the loading does not stop my application" - I don't follow why having it would allow the game to run smoothly if you're loading a scene, unless you're using the async methods.
Basically when I load the QCAR ARCamera it loads the dataset, and all trackables. This takes about 30sec to 1$$anonymous$$ if not longer. In this time the screen looks like it is frozen, I have a spinning cube (temporary) that stops spinning while the next scene loads up and I don't want that because I know my boss will hate it and I am trying to preempt the problem.
I don't know anything about QCAR ARCameras - a third party toolkit perhaps? But Presumably while the data is loading, you have no choice but to display something?
I still don't understand what it is you want to do: ou're saying you don't want the spinning cube? What do you want then?
No I meant I want a quick load without the screen looking like its frozen. The spinning cube is what I use to see if there is a problem with rendering the scene or not. When i click the button to go to the next scene this scene is frozen while being destroyed and the next loads up. I want to use Two Camera's the regular camera that see's my "menu" and another that loads up everything i t needs to run. then turn that camera off until it is needed in another scene. And yes QCAR is a unity extension for AugmentedReality applications by Qualcomm.
Thanks for all the info anyway.
Your answer
Follow this Question
Related Questions
How to show live camera on android inside scene??? 1 Answer
Open/Start Device Native Camera in Unity3D app using C# script, Without 3rd Party Plugins 1 Answer
make android camera video as the background of the unity scene? 0 Answers
Pinch-zoom camera 2 Answers
Setup for iPhone portrait game 0 Answers