Faisal Naseer
Faisal Naseer

Reputation: 4248

operation is not valid due to current state of object in Unity 3d

I am new to unity and practicing transform movements on camera. The code for the c# script that I am applying on it is.

using UnityEngine;
using System.Collections;
using System.Collections.Generic;


public class HelloWorld : MonoBehaviour {


    public float speed = 2f;
    // Use this for initialization
    void Start () {

    }

    // Update is called once per frame 
    void Update () {
        transform.Translate(new Vector3(speed,0,transform.position.z) * Time.deltaTime);

    }
}

but the console is showing errors stating: enter image description here

I searched for the problems and managed to get that the debugger is unable to get any thing from top of stack. But i am unable to figure out how its related to particular code and where actual problem exist?

Error Log: solution->Open( bstrSolution )m_CurrentEntriesPtr == NULL || !m_IsGettingEntries UnityEditorInternal.LogEntries:GetEntryInternal(Int32, LogEntry) UnityEditor.ConsoleWindow:OnGUI() (at C:\BuildAgent\work\d63dfc6385190b60\Editor\Mono\ConsoleWindow.cs:454) System.Reflection.MonoMethod:InternalInvoke(Object, Object[], Exception&) System.Reflection.MonoMethod:Invoke(Object, BindingFlags, Binder, Object[], CultureInfo) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222) System.Reflection.MethodBase:Invoke(Object, Object[]) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Reflection/MethodBase.cs:115) UnityEditor.HostView:Invoke(String, Object) (at C:\BuildAgent\work\d63dfc6385190b60\Editor\Mono\GUI\DockArea.cs:241) UnityEditor.HostView:Invoke(String) (at C:\BuildAgent\work\d63dfc6385190b60\Editor\Mono\GUI\DockArea.cs:234) UnityEditor.DockArea:OnGUI() (at C:\BuildAgent\work\d63dfc6385190b60\Editor\Mono\GUI\DockArea.cs:671) [C:\BuildAgent\work\d63dfc6385190b60\Editor/Src/EditorMonoConsole.h line 90] (Filename: C:/BuildAgent/work/d63dfc6385190b60/Editor/Mono/ConsoleWindow.cs Line: 454) m_CurrentEntriesPtr == NULL || !m_IsGettingEntries UnityEditorInternal.LogEntries:GetEntryInternal(Int32, LogEntry) UnityEditor.ConsoleWindow:OnGUI() (at C:\BuildAgent\work\d63dfc6385190b60\Editor\Mono\ConsoleWindow.cs:458) System.Reflection.MonoMethod:InternalInvoke(Object, Object[], Exception&) System.Reflection.MonoMethod:Invoke(Object, BindingFlags, Binder, Object[], CultureInfo) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222) System.Reflection.MethodBase:Invoke(Object, Object[]) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Reflection/MethodBase.cs:115) UnityEditor.HostView:Invoke(String, Object) (at C:\BuildAgent\work\d63dfc6385190b60\Editor\Mono\GUI\DockArea.cs:241) UnityEditor.HostView:Invoke(String) (at C:\BuildAgent\work\d63dfc6385190b60\Editor\Mono\GUI\DockArea.cs:234) UnityEditor.DockArea:OnGUI() (at C:\BuildAgent\work\d63dfc6385190b60\Editor\Mono\GUI\DockArea.cs:671) [C:\BuildAgent\work\d63dfc6385190b60\Editor/Src/EditorMonoConsole.h line 90] (Filename: C:/BuildAgent/work/d63dfc6385190b60/Editor/Mono/ConsoleWindow.cs Line: 458) InvalidOperationException: Operation is not valid due to the current state of the object at System.Collections.Stack.Peek () [0x0000c] in /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Collections/Stack.cs:321 at UnityEngine.GUILayoutUtility.EndLayoutGroup () [0x0001b] in C:\BuildAgent\work\d63dfc6385190b60\artifacts\EditorGenerated\GUILayoutUtility.cs:223 at UnityEditor.SplitterGUILayout.EndVerticalSplit () [0x00000] in C:\BuildAgent\work\d63dfc6385190b60\Editor\Mono\GUI\Splitter.cs:491 at UnityEditor.ConsoleWindow.OnGUI () [0x00761] in C:\BuildAgent\work\d63dfc6385190b60\Editor\Mono\ConsoleWindow.cs:488 at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (object,object[],System.Exception&) at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x000d0] in /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222

Upvotes: 0

Views: 2520

Answers (1)

Milad Qasemi
Milad Qasemi

Reputation: 3059

transform.Translate(Vector3.right * speed * Time.deltaTime);

Upvotes: 1

Related Questions