1

so I'm creating a simple 2D game in unity and at some point, I'm getting a few errors I think it's because I'm using an old way of writing so if someone can give me a modern way of writing the C# code it will help me very much

Here is the code :

    using UnityEngine;

public class PlayerMovement : MonoBehaviour
{
    public float moveSpeed;

    public Rigidbody2D rb;
    private Vector3 velocity = Vector3.zero;

    void FixedUpdate()
    {
        float horizontalMovement = Input.GetAxis("Horizontal") * moveSpeed * Time.deltaTime;

        MovePlayer(horizontalMovement);
    }

    void MovePlayer(float _horizontalMovement)
    {
        Vector3 targetVelocity = new Vector2(_horizontalMovement, rb.velocity.y);
        rb.velocity = Vector3.SmoothDamp(rb.velocity, targetVelocity, ref velocity, .05f);
    }
}

And here are the errors :

Error detecting Visual Studio installations: System.ComponentModel.Win32Exception (0x80004005): ApplicationName='C:\Users\Developers Institute\Tom's Adventure\Library\PackageCache\[email protected]\Editor\VSWhere\vswhere.exe', CommandLine='-prerelease -format json -utf8', CurrentDirectory='', Native error= The system cannot find the file specified.

UnityEngine.Debug:LogError (object) Microsoft.Unity.VisualStudio.Editor.VisualStudioEditor:DiscoverInstallations () (at Library/PackageCache/[email protected]/Editor/VisualStudioEditor.cs:59) Microsoft.Unity.VisualStudio.Editor.AsyncOperation`1<Microsoft.Unity.VisualStudio.Editor.IVisualStudioInstallation[]>:b__6_0 (object) (at Library/PackageCache/[email protected]/Editor/AsyncOperation.cs:38) System.Threading._ThreadPoolWaitCallback:PerformWaitCallback ()

Error while executing command: C:\Users\Developers Institute\Tom's Adventure\Library\PackageCache\[email protected]\hostwin\lld -flavor link /dll /DEBUG /pdb:"C:\Users\Developers Institute\Tom's Adventure\Temp\Burst\burst-aotgjyrtly5.re9\634edd43564d5aeb45f9bce68c886425.pdb" /pdbaltpath:"C:\Users\Developers Institute\Tom's Adventure\Library\BurstCache\JIT\634edd43564d5aeb45f9bce68c886425.pdb" /noentry /nodefaultlib /out:"C:\Users\Developers Institute\Tom's Adventure\Temp\Burst\burst-aotgjyrtly5.re9\634edd43564d5aeb45f9bce68c886425.dll" "C:\Users\Developers Institute\Tom's Adventure\Library\PackageCache\[email protected]\.Runtime\libs\burstRTL_w64.lib" /threads:1 "C:\Users\Developers Institute\Tom's Adventure\Temp\Burst\burst-aotgjyrtly5.re9\lib_burst_generated_part_.obj"

While compiling job: System.Void Unity.Burst.Intrinsics.X86::DoSetCSRTrampoline(System.Int32) at :line 0

Unexpected exception Burst.Compiler.IL.Aot.AotLinkerException: The native link step failed Error while executing command: C:\Users\Developers Institute\Tom's Adventure\Library\PackageCache\[email protected]\hostwin\lld -flavor link /dll /DEBUG /pdb:"C:\Users\Developers Institute\Tom's Adventure\Temp\Burst\burst-aotgjyrtly5.re9\634edd43564d5aeb45f9bce68c886425.pdb" /pdbaltpath:"C:\Users\Developers Institute\Tom's Adventure\Library\BurstCache\JIT\634edd43564d5aeb45f9bce68c886425.pdb" /noentry /nodefaultlib /out:"C:\Users\Developers Institute\Tom's Adventure\Temp\Burst\burst-aotgjyrtly5.re9\634edd43564d5aeb45f9bce68c886425.dll" "C:\Users\Developers Institute\Tom's Adventure\Library\PackageCache\[email protected]\.Runtime\libs\burstRTL_w64.lib" /threads:1 "C:\Users\Developers Institute\Tom's Adventure\Temp\Burst\burst-aotgjyrtly5.re9\lib_burst_generated_part_.obj". Check previous exception in the log - linker command line : "C:\Users\Developers Institute\Tom's Adventure\Library\PackageCache\[email protected]\hostwin\lld -flavor link /dll /DEBUG /pdb:"C:\Users\Developers Institute\Tom's Adventure\Temp\Burst\burst-aotgjyrtly5.re9\634edd43564d5aeb45f9bce68c886425.pdb" /pdbaltpath:"C:\Users\Developers Institute\Tom's Adventure\Library\BurstCache\JIT\634edd43564d5aeb45f9bce68c886425.pdb" /noentry /nodefaultlib /out:"C:\Users\Developers Institute\Tom's Adventure\Temp\Burst\burst-aotgjyrtly5.re9\634edd43564d5aeb45f9bce68c886425.dll" "C:\Users\Developers Institute\Tom's Adventure\Library\PackageCache\[email protected]\.Runtime\libs\burstRTL_w64.lib" /threads:1 "C:\Users\Developers Institute\Tom's Adventure\Temp\Burst\burst-aotgjyrtly5.re9\lib_burst_generated_part_.obj"" at Burst.Compiler.IL.Aot.AotNativeLinkBase.RunNativeLinkerTool (System.String command, System.String arguments, System.String errorMessage, System.String commandType, System.String workingDirectory, System.Boolean muteOutputs) [0x0008b] in <685f0c65f2a448a78ba2734aa17d6be3>:0 at Burst.Compiler.IL.Aot.AotNativeLinkLLVMWindows.Link (Burst.Backend.TargetCpu targetCpu, System.Collections.Generic.List'1[T] inputFiles, System.String outputFile, System.Boolean enableDebugInfo) [0x001b0] in <685f0c65f2a448a78ba2734aa17d6be3>:0 at Burst.Compiler.IL.Aot.AotCompiler.Link (System.Collections.Generic.List`1[T] groups, System.String nameSuffix, Burst.Compiler.IL.Aot.AotCompilerOptions compilerOptions, System.IO.TextWriter consoleOut, System.IO.TextWriter consoleError) [0x001f8] in <685f0c65f2a448a78ba2734aa17d6be3>:0 at Burst.Compiler.IL.Jit.Providers.BaseOnDiskProvider.CommonDiskCompileModule (Burst.Backend.Module module, Burst.Compiler.IL.NativeCompiler nativeCompiler, Burst.Compiler.IL.NativeCompilerOptions options, Burst.Compiler.IL.Jit.JitOptions jitOptions, Burst.Compiler.IL.Helpers.Hash128& moduleHash) [0x000b2] in <685f0c65f2a448a78ba2734aa17d6be3>:0 at Burst.Compiler.IL.Jit.Providers.OnDiskJitProvider.BeginCompileModule (Burst.Backend.Module module, Burst.Compiler.IL.NativeCompiler nativeCompiler, Burst.Compiler.IL.NativeCompilerOptions options, Burst.Compiler.IL.Jit.JitOptions jitOptions, Burst.Compiler.IL.Helpers.Hash128& moduleHash, Burst.Compiler.IL.Jit.JitCacheManager jitCacheManager, Burst.Compiler.IL.Jit.GetExternalFunctionPointerDelegate getExternalFunctionPointer, System.Action& invokeBurstInitialize) [0x00000] in <685f0c65f2a448a78ba2734aa17d6be3>:0 at Burst.Compiler.IL.Jit.JitCompiler.CompileMethodInternal (Burst.Compiler.IL.Jit.JitResult result, System.Collections.Generic.List'1[T] methodsToCompile, Burst.Compiler.IL.Jit.JitOptions jitOptions) [0x00677] in <685f0c65f2a448a78ba2734aa17d6be3>:0 at Burst.Compiler.IL.Jit.JitCompiler.CompileMethods (Burst.Compiler.IL.Jit.JitMethodGroupRequest& request, Burst.Compiler.IL.Jit.JitCompilationRequestType requestType) [0x00209] in <685f0c65f2a448a78ba2734aa17d6be3>:0 at Burst.Compiler.IL.Jit.JitCompiler.CompileMethod (Burst.Compiler.IL.Jit.MethodReferenceWithMethodRefString method, Burst.Compiler.IL.Jit.JitOptions jitOptions, Burst.Compiler.IL.Jit.JitCompilationRequestType requestType) [0x00023] in <685f0c65f2a448a78ba2734aa17d6be3>:0 at Burst.Compiler.IL.Jit.JitCompilerService+CompilerThreadContext.Compile (Burst.Compiler.IL.Jit.JitCompilerService+CompileJob job, Burst.Compiler.IL.Jit.JitCompilationRequestType requestType) [0x00491] in <685f0c65f2a448a78ba2734aa17d6be3>:0

While compiling job: System.Void Unity.Burst.Intrinsics.X86::DoSetCSRTrampoline(System.Int32) at :line 0

Yeah I know it's a lot sorry about that I'm still a beginner

2
  • I am not exactly sure what all of the other errors mean, but they could be dependent on the first error. In it it says that it was unable to access a file called vswhere.exe. If you could go to this file path and see if you have it: C:\Users\Developers Institute\Tom's Adventure\Library\PackageCache\[email protected]\Editor\VSWhere\ Commented Jan 4, 2022 at 12:38
  • 2
    These errors seem to be in no way related to anything in the code you shared ... Are these compile time or runtime errors? Commented Jan 4, 2022 at 13:40

1 Answer 1

3

Try going to Edit>Preferences>External Tools> Set your External Script editor to the correct version of vs, and then click "Regenerate project Files" button.

I see errors like this in my projects from time to time, and this almost always seems to fix it.

Sign up to request clarification or add additional context in comments.

1 Comment

okay I'll do that, thank you very much

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.