macos – Mac unity not working (error message)

Upon opening a new project or template the unity launcher dies and shows the errror message

Could not find Unity Package Manager local server application at (/Applications/Unity/Hub/Editor/2020.3.15f1/ Missing files could be the result of an antivirus action or a corrupt Unity installation.

If I diagnose it says

❓ UPM health check (UNKNOWN)
Start the UPM process and call its health endpoint

Could not find UPM executable at path ‘/Applications/Unity/Hub/Editor/2020.3.15f1/’

Anyone that cane help it would be greatly appreciated

unity – Scenes do not stop showing “(is loading)”

I want to rebuild the RE4 game behaviour.

In RE4, the inventory screen is a scene of its own.

In Unity, the scenes which are loaded additively inherit the skybox / lights from the first scene loaded.

That is why I start my game with an empty scene without any lights.
Else, if I would load the inventory level when it’s actually needed, it would inherit the lights from the currently loaded scene.

To avoid this, I have established the following game logic:

The first scene a black scene with just a single, empty gameobject. This gameobject has a script on it that loads the other scenes:

using UnityEngine;
using UnityEngine.SceneManagement;

public class StartupScript : MonoBehaviour
    AsyncOperation _InventoryScene;
    AsyncOperation _FirstLevel;

    void Start()
        //load the inventory scene so that we can quickly show it when the user presses the "Inventory" key.
        _InventoryScene = SceneManager.LoadSceneAsync("InventoryScene", LoadSceneMode.Additive);
        _InventoryScene.allowSceneActivation = false; //we make it so that it is not shown

        //Instead, we load the first level
        _FirstLevel = SceneManager.LoadSceneAsync("Level1Scene", LoadSceneMode.Additive);
        _FirstLevel.allowSceneActivation = true;//start the game by showing Level 1 scene

For some reason however, Unity does not show the level.
Instead, both scenes stay at “(is loading)”.

enter image description here

What am I missing?

Thank you!

Edit: When I do not load the InventoryScene first, the Level scene loads without any problems.

Edit2: When I load the InventoryScene at last, the InventoryScene stays at “(is loading)”.

enter image description here

unity – Checking if a base class type is of child class and accessing properties

I’m working on an inventory system similar to the Resident Evil games for a game jam. I wanted to practice using a little bit of inheritance, as well as ScriptableObjects as data containers, but I’m afraid I might have programmed myself into a corner.

I first declared an Item class

(CreateAssetMenu(fileName = "New Item", menuName = "Items/Item"))
public class Item : ScriptableObject
public string itemName = "Default Item";
public string itemDescription = "An item.";
public string itemID = "00";
public int quantity = 1;

public Sprite itemIcon;

public bool isStackable = false;

public static int idCounter = 0;

public enum ItemTypes

ItemTypes itemType;

and I derived an Ammo subclass among others, which has an extra AmmoType enum. At some point in my inventory code, I have an AddToInventory(Item item) method that takes an Item and adds it to a playerInventory list.

I’m now trying to stack ammo instead of adding to a new slot, so I was intending to check if the item about to be added has the same AmmoType by running through the list. Something like this pseudocode:

void AddToInventory(Item item)
  foreach (Item i in playerInventory)
    if ((Ammo)item.itemType == (Ammo)i.itemType)
       // Stack bullets

Of course, it’s not possible to cast like this. Is there any other way to check for the argument’s properties, assuming it is of a certain subclass?

C# / Unity : how to use in a child class a variable created in a base class?

I’m just starting to learn C# and I have a very basic problem regarding classes and inheritance. Basically, I have created a Plant class the regroups the basic functionnalities of a plant, and then I created a Grass class that will be attached to a Grass object in my game.
And I wanted to be able to intialize some variables (like age or birthTime) in the Plant class, and then access them in the Grass class; like this, when I will create another type of plant (flower for example), I would not need to initialize these caracteristics.

Here is my Plant class, where I initialize the age and birthTime variables:

enter image description here

And here is my Grass class, where I would want to access these variables but I can’t to it… Could someone explain to me how to do it pls? Thanks!!

enter image description here

virtual reality – Unity XR: Get boundary world position

I’m trying to create something simular to “Everest VR”‘s “Stand on the footprint” system.

The way it works is the game get’s the XR boundary, places a footprints texture in the corner of the play area and rotates the footprints towards the center of the playarea.

Now this isn’t too hard, I’m currently developing on Oculus Quest and I’m using:

using Unity.XR.Oculus;

public GameObject PlayAreaVisual; // A visual reference of what should be the playarea 
bool oculusPlayAreaSet = Boundary.GetBoundaryDimensions(Boundary.BoundaryType.PlayArea, out Vector3 dim);

PlayAreaVisual.transform.localScale = new Vector3(dim.x, 0.1f, dim.z);

to get the size of the playarea. The issue is that if the user resets the camera / “Reset view” by holding the Oculus button, it’s as if the XR system doesn’t understand that the camera has been reset, and uses the camera reset as an offset and doesn’t show the “real world boundaries”.

Oculus Quest boundary is offset due to resetting the camera

In the screenshot you can see the Vector3 which is dim from Boundary.GetBoundaryDimensions(Boundary.BoundaryType.PlayArea, out Vector3 dim);
This gives the size of the boundary but I still don’t know the correct position

I even tried having two custom play area objects, one on the camera offset, and one on the XR Rig root, but they end up overlapping

Unity inspector

TLDR; Using the Oculus Quest “Reset View” makes Unity “forgot” where the boundry is supposed to be

Question: How do you get the boundary world position / XR rig offset?

Blending between multiple textures with Unity CG Shader

I’ve been trying my hand at blending between 2 or more textures, so far I found I can lerp between Colors quite easily, but this lacks the detail I’m looking for. So I’m trying to blend 2 or 4 textures to start with. It’s a terrain generator shader, so based on the ‘depth’ I want the textures to change and blend.

Here’s my finished shader (not working; the terrain stays white at all depths):

Obviously void surf is where most of the magic happens. And yes I did set the textures I want in the inspector, it’s not that.

Shader "Custom/Terrain1"
        _RockInnerShallow ("Rock Inner Shallow", 2D) = "white" {}
        _RockInnerDeep ("Rock Inner Deep", 2D) = "white" {}
        _RockLight ("Rock Light", Color) = (1,1,1,1)
        _RockDark ("Rock Dark", Color) = (1,1,1,1)
        _GrassLight ("Grass Light", 2D) = "white" {}
        _GrassDark ("Grass Dark", 2D) = "white" {}

        _Color ("Color", Color) = (1,1,1,1)
        _Blend ("Texture Blend", Range(0,1)) = 0.0
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _Glossiness ("Smoothness", Range(0,1)) = 0.5
        _Test ("Test", Float) = 0.0

        _NoiseTex("Noise Texture", 2D) = "White" {}
        Tags { "RenderType"="Opaque" }
        LOD 200

        // Physically based Standard lighting model, and enable shadows on all light types
        #pragma surface surf Standard fullforwardshadows

        // Use shader model 3.0 target, to get nicer looking lighting
        #pragma target 3.0
        sampler2D _RockInnerDeep;
        sampler2D _RockInnerShallow;
        sampler2D _GrassDark;
        sampler2D _GrassLight;
        sampler2D _MainTex;
        sampler3D DensityTex;
        sampler2D _NoiseTex;

        struct Input
            float2 uv_MainTex;
            float3 worldNormal;
            float3 worldPos;
            float2 uv_RockInnerDeep;
            float2 uv_RockInnerShallow;
            float2 uv_GrassDark;
            float2 uv_GrassLight;

        half _Blend;
        half _Glossiness;
        fixed4 _Color;
        float4 _RockInnerShallow;
        float4 _RockInnerDeep;
        float4 _RockLight;
        float4 _RockDark;
        float4 _GrassLight;
        float4 _GrassDark;
        float _Test;
        float planetBoundsSize;

        float oceanRadius;

        float4 triplanarOffset(float3 vertPos, float3 normal, float3 scale, sampler2D tex, float2 offset) {
            float3 scaledPos = vertPos / scale;
            float4 colX = tex2D (tex, scaledPos.zy + offset);
            float4 colY = tex2D(tex, scaledPos.xz + offset);
            float4 colZ = tex2D (tex,scaledPos.xy + offset);
            // Square normal to make all values positive + increase blend sharpness
            float3 blendWeight = normal * normal;
            // Divide blend weight by the sum of its components. This will make x + y + z = 1
            blendWeight /= dot(blendWeight, 1);
            return colX * blendWeight.x + colY * blendWeight.y + colZ * blendWeight.z;

        float3 worldToTexPos(float3 worldPos) {
            return worldPos / planetBoundsSize + 0.5;

        void surf (Input IN, inout SurfaceOutputStandard o)

            float3 t = worldToTexPos(IN.worldPos);
            float density = tex3D(DensityTex, t);
            // 0 = flat, 0.5 = vertical, 1 = flat (but upside down)
            float steepness = 1 - (dot(normalize(IN.worldPos), IN.worldNormal) * 0.5 + 0.5);
            float dstFromCentre = length(IN.worldPos);

            float4 noise = triplanarOffset(IN.worldPos, IN.worldNormal, 30, _NoiseTex, 0);
            float4 noise2 = triplanarOffset(IN.worldPos, IN.worldNormal, 50, _NoiseTex, 0);
            //float angle01 = dot(normalize(IN.worldPos), IN.worldNormal) * 0.5 + 0.5;
            //o.Albedo = lerp(float3(1,0,0), float3(0,1,0), smoothstep(0.4,0.6,angle01));

            float metallic = 0;
            float rockMetalStrength = 0.4;
            float threshold = 0.005;
            if (density < -threshold) {
                float rockDepthT = saturate(abs(density + threshold) * 20);
                fixed4 c  = lerp(tex2D (_RockInnerShallow, IN.uv_RockInnerShallow),
                                tex2D (_RockInnerDeep, IN.uv_RockInnerDeep), rockDepthT) * _Color;
                o.Albedo = c.rgb;
                o.Alpha = c.a;
                //o.Albedo = lerp(_RockInnerShallow, _RockInnerDeep, rockDepthT);
                metallic = lerp(rockMetalStrength, 1, rockDepthT);
            else {
                fixed4 grassCol = lerp(tex2D (_GrassLight, IN.uv_GrassLight),
                                       tex2D (_GrassDark, IN.uv_GrassDark), noise.r);
                //float4 grassCol = lerp(_GrassLight, _GrassDark, noise.r);
                int r = 10;
                fixed4 rockCol = lerp(_RockLight, _RockDark, (int)(noise2.r*r) / float(r));
                //float4 rockCol = lerp(_RockLight, _RockDark, (int)(noise2.r*r) / float(r));
                float n = (noise.r-0.4) * _Test;

                float rockWeight = smoothstep(0.24 + n, 0.24 + 0.001 + n, steepness);
                o.Albedo = lerp(grassCol, rockCol, rockWeight);
                //o.Albedo = steepness > _Test;
                metallic = lerp(0, rockMetalStrength, rockWeight);

            //o.Albedo = dstFromCentre > oceanRadius;

            //o.Albedo = metallic;

            o.Metallic = metallic;
            o.Smoothness = _Glossiness;
    FallBack "Diffuse"

unity – When should I start the SlowDown coroutine?

The SpeedUp coroutine is working fine as I wanted.

The transform starts moving down slowly falling down a bit then start rolling on the terrain.
While rolling on the terrain the player starts walking backward slowly from speed 0 to speed 1 but lerping the “Walk Backward” float parameter of the “Walking” state.

Now I want that just a bit before the transform stops rolling not stop rotating! but stop rolling a bit before he stops to start to slow down the player the “Walk Backward” float parameter from 1 to 0 so the player will stop at the same time with the transform.

I used at the bottom near the end of the script the flag hasStopped and set it to true but this flag show where the transform has stopped rotating not stopped rolling.

I want somehow to calculate when to start to slow down the “Walk Backward” so the player and the transform both will stop at the same time !!!!!

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Cinemachine;
using FIMSpace.FLook;

public class Rolling : MonoBehaviour
    public GameObject mainCam;
    public CinemachineFreeLook freeLookCamGameplay;
    public CinemachineFreeLook freeLookCamPickUp;
    public Transform player;
    public Transform crate;
    public Transform cube;
    public Animation anim;
    public UnlockCrate unlockCrate;
    public float timeToStopRolling;
    public float speed;
    public float waitBeforeSlowdown;
    public float startDrag;
    public float endDrag = 50;
    public float rotationSpeed;
    public static bool hasStopped = false;

    private bool crateOpenOnce = false;
    private bool alreadyRolling;
    private Rigidbody rb;
    private Quaternion defaultRotation;
    private Animator animator;
    private bool startSlow = true;
    private bool startSpeedUp = true;
    public float lerpTimeMultiplicator = 0.25f;

    private float timeElapsed = 0;
    private float lerpDuration = 3f;
    private float startValue = 1;
    private float endValue = 0;
    private float valueToLerp = 0;

    private void Start()
        rb = GetComponent<Rigidbody>();

        defaultRotation = rb.rotation;

        animator = player.GetComponent<Animator>();

    private void Update()
        var distance = Vector3.Distance(crate.position, player.position);
        if (distance < 1.7f && crateOpenOnce == false && unlockCrate.HasOpened())
            rb.isKinematic = false;
            crateOpenOnce = true;

        if(crateOpenOnce && startSpeedUp)
            startSpeedUp = false;

    private IEnumerator Slowdown()
        if (timeElapsed < lerpDuration)
            timeElapsed += Time.deltaTime;
            valueToLerp = Mathf.Lerp(startValue, endValue, timeElapsed / lerpDuration);
            animator.SetFloat("Walk Backward", valueToLerp);

            // Yield here
            yield return null;

    private IEnumerator SpeedUp()
        while(timeElapsed < lerpDuration)
            timeElapsed += Time.deltaTime;
            valueToLerp = Mathf.Lerp(endValue, startValue, timeElapsed / lerpDuration);
            animator.SetFloat("Walk Backward", valueToLerp);

            // Yield here
            yield return null;

    private void OnCollisionEnter(Collision collision)
        //NOTE: In general you should go for Tags instead of the name
        if ( == "Crate_0_0")
            if (crateOpenOnce)
                rb.drag = 0f;

                // Directly start a routine here (if none is already running)
                if (!alreadyRolling) StartCoroutine(RollingRoutine());

    private void OnCollisionExit(Collision collision)
        if ( == "Crate_0_0")

            var brain = mainCam.GetComponent<CinemachineBrain>();
            brain.m_DefaultBlend.m_Time = 1f;
            freeLookCamGameplay.enabled = false;
            freeLookCamPickUp.enabled = true;

    private Vector3 GetRandomDirection()
        var rnd = Random.insideUnitSphere;
        rnd.y = 0;
        return rnd.normalized;

    private IEnumerator RollingRoutine()
        // Just in case prevent concurrent routines
        if (alreadyRolling) yield break;

        // Block new routines from starting
        alreadyRolling = true;

        // Get the random direction for this routine
        var rollDirection = GetRandomDirection();

        // Roll for the given time within the FixedUpdate call
        for (var timePassed = 0f; timePassed < timeToStopRolling; timePassed += Time.deltaTime)
            // Wait until you are in FixedUpdate
            // the code after this is now executed within FixedUpdate
            yield return new WaitForFixedUpdate();

            rb.AddForce(Vector3.right /*rollDirection*/ * speed * Time.deltaTime);

        // Wait before slowing down
        yield return new WaitForSeconds(waitBeforeSlowdown);

        // Do slow down and rotate to default until both conditions are fulfilled
        var dragLerpFactor = 0f;
        // Store the original drag to reset it later
        var defaultDrag = rb.drag;
        while (!Mathf.Approximately(rb.velocity.sqrMagnitude, 0) || rb.rotation != defaultRotation)
            // Again wait until you are in FixedUpdate
            yield return new WaitForFixedUpdate();

            dragLerpFactor += Time.deltaTime * lerpTimeMultiplicator;
            rb.drag = Mathf.Lerp(startDrag, endDrag, dragLerpFactor);

            rb.MoveRotation(Quaternion.RotateTowards(rb.rotation, defaultRotation, rotationSpeed * Time.deltaTime));

        // Just to be sure to end with clean value assign once
        rb.rotation = defaultRotation;
        rb.drag = defaultDrag;
        rb.velocity =;

        hasStopped = true;


virtual reality – package-lock.json file for in Unity?

Since I’ve been asked to reformat my question, here it is :

Under Unity 2020 and behond…

I think that my package package-lock.json is corrupted, and block the fabrication of the build.

Could it be possible to :

  • Erase, or regenerate it ?

  • What damages it will create if I just delete the content of the folder ?


unity – How can I clamp rotation?

using UnityEngine;
using System;
using System.Collections;
using UnityEngine.UI;
using System.Collections.Generic;
using System.Linq;
using TMPro;

public class MyLookAt : MonoBehaviour
    public Transform target;
    public Transform objToRotate;

    void LateUpdate()
        Vector3 relativePos = target.position - objToRotate.position;
        Quaternion rotation = Quaternion.LookRotation(relativePos, Vector3.up);
        objToRotate.rotation = rotation;

I want to clamp on the Y(up/down) and the X(left/right) so if the target object is behind the player or out of the player seen sight slowly smooth return the player head to its original start rotation.

unity – How can I make the objToRotate speed to rotate depending on the target moving speed?

The player has these components: Animator, Rigidbody, Capsule Collider, Third Person Character (Script), Third Person User Control (Script), and the MyLookAT script.

The problem is if I drag the cube target too fast in the editor changing its position it will take some time for the objToRotate to rotate facing the target again. I want somehow to make that the objToRotate will know to set his own speed and to rotate fast/slow enough to face the target when moving the target.

I want the objToRotate to face the target in real-time when the target is moving not with delay.

using UnityEngine;
using System;
using System.Collections;

public class RotatingTest : MonoBehaviour
    public Transform target;
    public Transform objToRotate;
    public float speed = 1.0f;

    void LateUpdate()
        Vector3 targetDirection = target.position - objToRotate.position;
        float singleStep = speed * Time.deltaTime;

        Vector3 newDirection = Vector3.RotateTowards(objToRotate.forward, targetDirection, singleStep, 0.0f);

        Debug.DrawRay(objToRotate.position, newDirection,;

        objToRotate.rotation = Quaternion.LookRotation(newDirection);