- Home /
SerializedObject target has been destroyed. UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)
As soon as I click on the "Keyboard" button in my scene it takes me to scene(1) and enables MovementKeyboard script as I wanted, but the MovementKeyboard never runs becasue of the error SerializedObject target has been destroyed. UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr). I have rebuild all the lightings but still in gives the same error as soon as the scene changes.
Script of button --
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class ControlKeyboard : MonoBehaviour {
public MovementKeyboard ControlKEYBOARD;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
public void ButtonKeyboard()
{
ControlKEYBOARD = ControlKEYBOARD.GetComponent<MovementKeyboard>();
ControlKEYBOARD.enabled = true;
SceneManager.LoadScene(1);
}
}
MovementKeyboard Script attached to player-
public class MovementKeyboard : MonoBehaviour {
public Rigidbody rbKeyboard;
public float SidewaysForceKeyboard = 500f;
public float ForwardForceKeyboard = 8000f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void FixedUpdate ()
{
//Forward Movement
rbKeyboard.AddForce(0, 0, ForwardForceKeyboard * Time.deltaTime);
//right movement
if (Input.GetKey("d"))
{
rbKeyboard.AddForce(SidewaysForceKeyboard * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
}
//Left Movement
if (Input.GetKey("a"))
{
rbKeyboard.AddForce(-SidewaysForceKeyboard * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
}
}
}
Please help me out. Thankyou I have also attached the screenshots of the editor before and after clicking the button.
Answer by nathanwick · Dec 27, 2018 at 10:20 PM
I had the same problem. It's an editor error. I closed the editor and reopened it. Then everything was normal again.
in my case, this error comes from nowhere and gone after this classic general-purpose solution! thanks!
Answer by khooroko · Aug 10, 2018 at 01:30 AM
You may have enabled the MovementKeyboard in the original scene before loading scene(1), and when you load a scene normally all the objects in the previous scene are destroyed. Take a look at https://docs.unity3d.com/ScriptReference/Object.DontDestroyOnLoad.html. I think you just need to add that one line to the MovementKeyboard script (or any other script you attach to the player).
Answer by Sackstand · Jun 18, 2020 at 07:26 AM
sorry for Necro this Thread.
I had the same problem and a restart from Unity helps. But from time to time it came back. After a lot of testing around i found my problem. I use a wireless Keyboard and Mouse. every time when i get out of range or getting close to it the input delay raises and unity start to throw this error. even when i get back in range. only a restart will help until you lose connection again.
maybe this info will help someone.
testet with Unity 2019.3.14.f1
Answer by jonc113 · Oct 05, 2018 at 12:55 AM
I had this error. I deleted my Library folder and let the game rebuild it. Problem went away.
Answer by renren30 · Apr 21, 2020 at 10:56 AM
For me the NavMeshAgent caused the problem. If the "Stopping Distance" was set to 0 Unity showed this error. After i set it to 0.1 it worked without error.
Your answer
Follow this Question
Related Questions
Change to scene based on current scene 1 Answer
Using UI.Button to Load Another Scene? (using outdated tutorial video) 1 Answer
How to get Rect from scene Button ? 1 Answer
making and integrating Visual novel element in 3d game? 2 Answers
load level with gui button nested in a toggled window!!! 0 Answers