Right now, in order for a Simple XR Interactable to be found by the XR Interaction System, it needs to exist in the first, primary scene.
Even if you tell the SceneManager.SetActiveScene, the first scene in the list of loaded scenes is the one where the interaction system attempts to find objects.
This is easily reproducible at runtime by dragging objects between loaded scenes.
I’d like to have objects in additive-loaded scenes detectable by the interaction system for the sake of object management. Doing this now, the interaction system cannot detect them.
The Interaction Manager does not automatically attempt to locate and register interactables or interactors, it is the responsibility of the interactables and interactors themselves to register with the manager. You can set the Interaction Manager property in the Inspector or through scripting, and the interactable/interactor will register itself with that manager. If it is not set, it will first attempt to locate one using FindObjectOfType and then create one if it couldn’t find one.
However, that function can be tricky. During the first frame of entering Play mode, during Awake and OnEnable, objects in the Active Scene will only be able to find activated objects of that type within the Active Scene. This means that the interactors/interactables will only find an Interaction Manager if the manager is in the Active Scene during that time. The order of the Scenes in the Hierarchy shouldn’t matter. After that first frame, if you additive load another Scene that contains an interactor/interactable, there shouldn’t be any gotchas for finding the Interaction Manager contained in other scenes.
It should be possible to have objects in additive-loaded scenes be usable with the interaction system as long as you are aware of that limitation around the timing.
I’ll create an issue in our backlog to to improve this finding process so developers avoid getting tripped up on that.
I think there is still something amiss. I see your point about the XR Interaction Manager and the reference to it on a XR Interaction, but that doesn’t really answer why one scene works and the other doesn’t.
The problem appears to occur in this method:
int CheckCollidersBetweenPoints(Vector3 from, Vector3 to)
{
Array.Clear(m_RaycastHits, 0, k_MaxRaycastHits);
// Cast from last point to next point to check if there are hits in between
if (m_HitDetectionType == HitDetectionType.SphereCast && m_SphereCastRadius > 0f)
{
return Physics.SphereCastNonAlloc(from, m_SphereCastRadius, (to - from).normalized,
m_RaycastHits, Vector3.Distance(to, from), raycastMask, raycastTriggerInteraction);
}
return Physics.RaycastNonAlloc(from, (to - from).normalized,
m_RaycastHits, Vector3.Distance(to, from), raycastMask, raycastTriggerInteraction);
}
Right now I have 3 scenes in my hierarchy:
[game]
[scenery] ← active
[DontDestroyOnLoad]
I have my XR Interaction Manager in the DontDestroyOnLoad.
Previously, my [game] scene was set as active and my interaction was spawning in the [game] scene, but I recently messed around with some code that toggled the ActiveScene and shifted it to [scenery].
Now that [scenery] is considered active on load, all of the XR Interactions are spawning associated with that scene. No matter what I do, I cannot select the interaction now.
As soon as I drag it into the [game] scene, the interaction works immediately. If I drag it back into the [scenery] scene, it doesn’t work.
I just recreated the scenario with multiple scenes and haven’t been able to reproduce. I have a sinking suspicion that this is related to multiplayer and physics scenes
You will have to make sure that any interactable object is in the default physics scene. As you saw in the code you pasted, the XRRayInteractor.CheckCollidersBetweenPoints method uses the Physics class for raycasting which will only hit objects in the default physics scene. The section on Multi-scene physics in that blog post does a pretty good job of explaining the limitation along with the Multi-Scene Physics tutorial.
I’m not familiar with Mirror, but you may need to adjust some settings so that the other scenes are additively loaded without creating local physics scenes.
Hey, thanks for the reply! I did end up resolving it.
I had initially built my multiplayer tech around the MultipleAdditiveScenes demo because of the way I wanted to lay things out.
With that, came the example code that was adding the Scene with specific LoadSceneParameters.
These parameters would include this:
localPhysicsMode = LocalPhysicsMode.Physics3D
Once I removed the LocalPhysicsMode param from the scene params, my interactions started working more reliably.
I say more reliably, because now I can hover the object and detect. I still get some weird flicker / inconsistent physics, but it’s at least detectable in some sense now and I can debug from here.
That was a really frustrating issue to debug though, holy moly