How to fix the problem of Vuforia AR Camera in individual Scene, but not entire project?

2018-01-31

In my Unity version, I face a problem:

Working with 2017.3.0f3 and have enabled Vuforia for my project, however I have certain scenes that have no AR requirements. Enabling Vuforia means every scene currently is setup (at runtime) with an ARCamera which is not desired.

The solution is:

In the Specific Scene, add the following function to the Camera Script:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
void Awake(){
try
{
EventInfo evSceneLoaded = typeof(SceneManager).GetEvent("sceneLoaded");
Type tDelegate = evSceneLoaded.EventHandlerType;
MethodInfo attachHandler = typeof(VuforiaRuntime).GetMethod("AttachVuforiaToMainCamera", BindingFlags.NonPublic | BindingFlags.Static);
Delegate d = Delegate.CreateDelegate(tDelegate, attachHandler);
SceneManager.sceneLoaded -= d as UnityEngine.Events.UnityAction<Scene, LoadSceneMode>;
}
catch (Exception e)
{
Debug.LogWarning("Cant remove the AttachVuforiaToMainCamera action: " + e.ToString());
}
}

Comments: