// Tries to migrate the user to the target actor. // If targetActor == null, the user will be actorless. public void MigrateUserTo(VoosActor targetActor) { PlayMain pm = playMain.GetComponent <PlayMain>(); PlayerBody targetPlayerBody = targetActor?.GetPlayerBody(); if (targetActor != null && (!targetActor.GetIsPlayerControllable() || null == targetPlayerBody)) { targetActor.SetIsPlayerControllable(true); targetPlayerBody = targetActor.GetPlayerBody(); Debug.Assert(targetPlayerBody != null, "MigrateUserTo could not add a PlayerBody to target actor."); } pm.SetPlayerBody(targetPlayerBody); // If we are in play mode, we need to reparent the user body. // Otherwise this will be done later, when we enter play mode. if (!InEditMode()) { userBody.transform.SetParent(playMain.bodyParent); userBody.transform.localPosition = Vector3.zero; userBody.transform.localRotation = Quaternion.identity; } if (targetActor != null) { targetActor.RequestOwnership(); } VoosActor playMainActor = pm.GetPlayerActor(); Debug.Assert(targetActor == playMainActor, "MigrateUserTo didn't succeed, we wanted targetActor to be " + targetActor + " but PlayMain still has " + playMain); }