microsoft / ProjectAcoustics

Microsoft Project Acoustics
https://aka.ms/acoustics
Creative Commons Attribution 4.0 International
133 stars 21 forks source link

Problems when maincamera is injected procedurally #24

Open AndersMalmgren opened 4 years ago

AndersMalmgren commented 4 years ago

Hey guys. Sorry for spamming you today. :D

In our game we add the main camera on Scene load, we load the new level async and when the new level is loaded fully we create a new camera rig (VR camera rig).

The API does not like this, console gets spammed with null reference

NullReferenceException: Object reference not set to an instance of an object
AcousticsManager.InitAcoustics () (at Assets/Acoustics/Scripts/AcousticsManager.cs:74)
AcousticsManager.OnEnable () (at Assets/Acoustics/Scripts/AcousticsManager.cs:214)
NullReferenceException: Object reference not set to an instance of an object
AcousticsManager.UpdateProbesForGizmo () (at Assets/Acoustics/Scripts/AcousticsManager.cs:167)
AcousticsManager.Update () (at Assets/Acoustics/Scripts/AcousticsManager.cs:254)

I have tried to load the Manager dynamicly after the camera rig is added. Nothing works.

AndersMalmgren commented 4 years ago

If I disable the manager in the scene view. And from my code enable it after scene is loaded. It works. But feels like it would be neater if the API can handle this nativly.

MikeChemi commented 4 years ago

No worries, we're happy to help :)

You're correct that AcousticsManager only works if it is created after your MainCamera, otherwise you get lots of errors. Your workaround is what we would suggest for the time being. We'll add this use case to our list of scenarios to consider in future releases.

AndersMalmgren commented 4 years ago

Thanks, I wasn't able to create the manager from code. I had to put it in the scene and disable it. Than re-enable it from code when main camera was in scene, actually my camera wasn't even tagged as main camera, I think it's a bit fragile to use tags for anything, maybe think avout a more solid solution there for the long run :)

MikeChemi commented 4 years ago

If you're confident in your coding chops, you could always alter the manager script to take a Camera object as a public member instead of searching for the main camera. As long as the camera is set before the Manager is initialized, it doesn't really matter where the camera comes from.

AndersMalmgren commented 4 years ago

I really don't like changing vendor source code :) my workaround works for now :)

kegodin commented 4 years ago

Thanks for flagging this issue. It's tracked internally with ADO bug # 24773545.