DontDestroyOnLoad sigue llamando y provoca un error en el modo de juego
– UnityAssets3Free
hola , por aqui josel luis y para hoy os traigo
nueva pregunta curiosa
Estoy haciendo un corredor sin fin en 2d en el que implementé un código para la gravedad y el movimiento del jugador. Cuando agregué gravedad y velocidad al reproductor a través de un script adjunto a continuación y habilité el modo de reproducción, aparece una escena llamada «DontDestroyOnLoad» en la ventana de jerarquía y tiene un objeto llamado [Debug Updater] como un niño pegado a él. El guión del jugador está aquí:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class HeroCharacterController : MonoBehaviour
[SerializeField] LayerMask groundLayers;
private float gravity = -50f;
private CharacterController characterController;
private Vector3 velocity;
private bool isGrounded;
// Start is called before the first frame update
void Start()
characterController = GetComponent<CharacterController>();
// Update is called once per frame
void Update()
///Is Grounded
isGrounded = Physics.CheckSphere(transform.position, 0.1f, groundLayers, QueryTriggerInteraction.Ignore);
if(!isGrounded && velocity.y <0)
velocity.y = 0;
else
///Add Gravity
velocity.y += gravity * Time.deltaTime;
El script llamado «DebugUpdater» adjunto al Debug Updater está aquí:
namespace UnityEngine.Rendering
class DebugUpdater : MonoBehaviour
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterSceneLoad)]
static void RuntimeInit()
if (!Debug.isDebugBuild
void Update()
DebugManager.instance.UpdateActions();
if (DebugManager.instance.GetAction(DebugAction.EnableDebugMenu) != 0.0f)
DebugManager.instance.displayRuntimeUI = !DebugManager.instance.displayRuntimeUI;
if (DebugManager.instance.displayRuntimeUI && DebugManager.instance.GetAction(DebugAction.ResetAll) != 0.0f)
DebugManager.instance.Reset();
Este es el error que se está causando y mi secuencia de comandos no funciona porque el reproductor no se cae ni se mueve. El error:
ArgumentException: SceneManager.SetActiveScene failed; the internal DontDestroyOnLoad scene cannot be set active.
UnityEngine.SceneManagement.SceneManager.SetActiveScene (UnityEngine.SceneManagement.Scene scene) (at <028e4d71153d4ed5ac6bee0dfc08aa3b>:0)
UnityEditor.SceneHierarchy.TreeViewItemDoubleClicked (System.Int32 instanceID) (at <bd70c40e01f641bdb7d836e1e97755bc>:0)
UnityEditor.IMGUI.Controls.TreeViewController.HandleUnusedMouseEventsForItem (UnityEngine.Rect rect, UnityEditor.IMGUI.Controls.TreeViewItem item, System.Int32 row) (at <bd70c40e01f641bdb7d836e1e97755bc>:0)
UnityEditor.IMGUI.Controls.TreeViewController.DoItemGUI (UnityEditor.IMGUI.Controls.TreeViewItem item, System.Int32 row, System.Single rowWidth, System.Boolean hasFocus) (at <bd70c40e01f641bdb7d836e1e97755bc>:0)
UnityEditor.IMGUI.Controls.TreeViewController.IterateVisibleItems (System.Int32 firstRow, System.Int32 numVisibleRows, System.Single rowWidth, System.Boolean hasFocus) (at <bd70c40e01f641bdb7d836e1e97755bc>:0)
UnityEditor.IMGUI.Controls.TreeViewController.OnGUI (UnityEngine.Rect rect, System.Int32 keyboardControlID) (at <bd70c40e01f641bdb7d836e1e97755bc>:0)
UnityEditor.SceneHierarchy.DoTreeView (System.Single searchPathHeight) (at <bd70c40e01f641bdb7d836e1e97755bc>:0)
UnityEditor.SceneHierarchy.OnGUI (UnityEngine.Rect rect) (at <bd70c40e01f641bdb7d836e1e97755bc>:0)
UnityEditor.SceneHierarchyWindow.DoSceneHierarchy () (at <bd70c40e01f641bdb7d836e1e97755bc>:0)
UnityEditor.SceneHierarchyWindow.OnGUI () (at <bd70c40e01f641bdb7d836e1e97755bc>:0)
System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <eae584ce26bc40229c1b1aa476bfa589>:0)
Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <eae584ce26bc40229c1b1aa476bfa589>:0)
System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at <eae584ce26bc40229c1b1aa476bfa589>:0)
UnityEditor.HostView.Invoke (System.String methodName, System.Object obj) (at <bd70c40e01f641bdb7d836e1e97755bc>:0)
UnityEditor.HostView.Invoke (System.String methodName) (at <bd70c40e01f641bdb7d836e1e97755bc>:0)
UnityEditor.HostView.InvokeOnGUI (UnityEngine.Rect onGUIPosition, UnityEngine.Rect viewRect) (at <bd70c40e01f641bdb7d836e1e97755bc>:0)
UnityEditor.DockArea.DrawView (UnityEngine.Rect viewRect, UnityEngine.Rect dockAreaRect) (at <bd70c40e01f641bdb7d836e1e97755bc>:0)
UnityEditor.DockArea.OldOnGUI () (at <bd70c40e01f641bdb7d836e1e97755bc>:0)
UnityEngine.UIElements.IMGUIContainer.DoOnGUI (UnityEngine.Event evt, UnityEngine.Matrix4x4 parentTransform, UnityEngine.Rect clippingRect, System.Boolean isComputingLayout, UnityEngine.Rect layoutSize, System.Action onGUIHandler, System.Boolean canAffectFocus) (at <a6a8a08b59d34373858eada2d852ad38>:0)
UnityEngine.UIElements.IMGUIContainer.HandleIMGUIEvent (UnityEngine.Event e, UnityEngine.Matrix4x4 worldTransform, UnityEngine.Rect clippingRect, System.Action onGUIHandler, System.Boolean canAffectFocus) (at <a6a8a08b59d34373858eada2d852ad38>:0)
UnityEngine.UIElements.IMGUIContainer.HandleIMGUIEvent (UnityEngine.Event e, System.Action onGUIHandler, System.Boolean canAffectFocus) (at <a6a8a08b59d34373858eada2d852ad38>:0)
UnityEngine.UIElements.IMGUIContainer.HandleIMGUIEvent (UnityEngine.Event e, System.Boolean canAffectFocus) (at <a6a8a08b59d34373858eada2d852ad38>:0)
UnityEngine.UIElements.IMGUIContainer.SendEventToIMGUI (UnityEngine.UIElements.EventBase evt, System.Boolean canAffectFocus) (at <a6a8a08b59d34373858eada2d852ad38>:0)
UnityEngine.UIElements.IMGUIContainer.HandleEvent (UnityEngine.UIElements.EventBase evt) (at <a6a8a08b59d34373858eada2d852ad38>:0)
UnityEngine.UIElements.EventDispatchUtilities.PropagateEvent (UnityEngine.UIElements.EventBase evt) (at <a6a8a08b59d34373858eada2d852ad38>:0)
UnityEngine.UIElements.MouseEventDispatchingStrategy.DispatchEvent (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel panel) (at <a6a8a08b59d34373858eada2d852ad38>:0)
UnityEngine.UIElements.EventDispatcher.ApplyDispatchingStrategies (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel panel, System.Boolean imguiEventIsInitiallyUsed) (at <a6a8a08b59d34373858eada2d852ad38>:0)
UnityEngine.UIElements.EventDispatcher.ProcessEvent (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel panel) (at <a6a8a08b59d34373858eada2d852ad38>:0)
UnityEngine.UIElements.EventDispatcher.ProcessEventQueue () (at <a6a8a08b59d34373858eada2d852ad38>:0)
UnityEngine.UIElements.EventDispatcher.OpenGate () (at <a6a8a08b59d34373858eada2d852ad38>:0)
UnityEngine.UIElements.EventDispatcherGate.Dispose () (at <a6a8a08b59d34373858eada2d852ad38>:0)
UnityEngine.UIElements.EventDispatcher.ProcessEvent (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel panel) (at <a6a8a08b59d34373858eada2d852ad38>:0)
UnityEngine.UIElements.EventDispatcher.Dispatch (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel panel, UnityEngine.UIElements.DispatchMode dispatchMode) (at <a6a8a08b59d34373858eada2d852ad38>:0)
UnityEngine.UIElements.BaseVisualElementPanel.SendEvent (UnityEngine.UIElements.EventBase e, UnityEngine.UIElements.DispatchMode dispatchMode) (at <a6a8a08b59d34373858eada2d852ad38>:0)
UnityEngine.UIElements.UIElementsUtility.DoDispatch (UnityEngine.UIElements.BaseVisualElementPanel panel) (at <a6a8a08b59d34373858eada2d852ad38>:0)
UnityEngine.UIElements.UIElementsUtility.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr) (at <a6a8a08b59d34373858eada2d852ad38>:0)
UnityEngine.GUIUtility.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr) (at <023156577e4f4156adf0f4b3a3fedf85>:0)
Además, también adjunté la captura de pantalla de mi juego en el modo de juego y en el modo de escena. Capturas de pantalla:
¡Agradezco anticipadamente!
1 respuesta 1
Esto causa el problema:
isGrounded = Physics.CheckSphere(transform.position, 0.1f, groundLayers, QueryTriggerInteraction.Ignore);
La solución es usar solo dos argumentos para este método:
Physics.CheckSphere(transform.position, 0.1f);
nota: si aun no se resuelve tu pregunta por favor dejar un comentario y pronto lo podremos de nuevo , muchas gracias
sin mas,espero que te funcione