How do I make scale of a GameObject persist in Unity?

I’m currently developing a Hololens application and I’ve used Microsoft’s official spatial anchor documentation to create a voice command that can persistently anchor a GameObject in place. So if I exit the application and start it again, the GameObject will be in the same position and orientation as I had left it. However, a problem is that it doesn’t save the scale of the object. So what I need to do is somehow save the scale of the GameObject at the time at which I last manipulated it, and then upon startup, retrieve this saved scale and apply it dynamically to my GameObject.

I know what I have to do, I just don’t know how to do it. Does anyone have any experience doing this and could tell me what to do?

Назначение постоянной скорости Unity Vector2

Пример склона

При перемещении по склонам, скорость изменяется, нужно задать постоянную скорость y но что бы х можно было изменять при необходимости.

rb.velocity = new Vector2(direction * speed, speedy); 

Можно ли, например, нормализировать только y?

Unity – Parameter does not exist

I’ve tried asking on the Unity forum, but as always, I little to no response, and this is really frustrating me. I’ve never had this issue before when setting up animations or Animation Controllers. As far as I’m aware, I’ve set everything up correctly, but my open animation for my chest won’t play and it just keeps saying Parameter ‘open’ does not exist. It’s in the correct animation controller, the controller has been assigned, the parameter is there, I’ve specified my Transitions, I’ve added the code, so I’m not sure what I’m overlooking. 🙁

These are the two scripts I have…

using System.Collections; using System.Collections.Generic; using UnityEngine;  public class OpenChest : MonoBehaviour {     public bool allowOpen;      public void OnTriggerEnter(Collider other)     {         if (other.gameObject.CompareTag("Player"))         {             allowOpen = true;         }     } }

using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement;  public class PlayerController : MonoBehaviour {     public Animator anim;     public float moveSpeed;     public float jumpForce;     public bool jumped;     public bool allowInteract = false;     public float gravityScale;     public float knockBackForce;     public float knockBackTime;     public float invincibilityLength;     public Renderer playerRenderer;     public Material textureChange;     public Material textureDefault;     public bool allowCombat;     public bool allowJump;     public static bool canMove;     public GameObject chest;      [SerializeField]     private HurtEnemy damageEnemy;     private Vector2 moveDirection;     private Vector2 moveHorizontal;     private Vector2 moveVertical;     private float knockBackCounter;     private float invincibilityCounter;     private CharacterController controller;     private Quaternion targetRot;     private bool headingLeft = false;     private Pickup pickupWeapon;     private OpenChest openChest;      void Awake()     {         controller = GetComponent<CharacterController>();         openChest = chest.GetComponent<OpenChest>();         anim = GetComponent<Animator>();         //damageEnemy = projectile.GetComponent<HurtEnemy>();     }      void Start()     {         Cursor.visible = false;         pickupWeapon = FindObjectOfType<Pickup>();         canMove = true;         targetRot = transform.rotation;         if (SceneManager.GetActiveScene() == SceneManager.GetSceneByName("start_area"))         {             allowCombat = false;             allowJump = true;         }         if (SceneManager.GetActiveScene() == SceneManager.GetSceneByName("hut_interior"))         {             allowCombat = false;             allowJump = false;         }         if (SceneManager.GetActiveScene() == SceneManager.GetSceneByName("start_area 2"))         {             allowCombat = false;             allowJump = true;         }         if (SceneManager.GetActiveScene() == SceneManager.GetSceneByName("level 1, room 1"))         {             allowCombat = true;             allowJump = true;         }         if (SceneManager.GetActiveScene() == SceneManager.GetSceneByName("level 1, room 2"))         {             allowCombat = true;             allowJump = true;         }     }      void Update()     {         if (knockBackCounter <= 0 && canMove)         {             moveHorizontal.x = Input.GetAxis("Horizontal");             float moveHorizontalSnap = Input.GetAxis("Horizontal");             float moveVertical = Input.GetAxis("Vertical");             //moveVertical.y = Input.GetAxis("Vertical");             moveDirection = new Vector2(moveHorizontal.x * moveSpeed, moveDirection.y);             controller.Move(moveDirection * Time.deltaTime);              //Adds character rotation when changing direction horizontally             if ((moveHorizontal.x < 0f && !headingLeft) || (moveHorizontal.x > 0f && headingLeft))             {                 if (moveHorizontal.x < 0f) targetRot = Quaternion.Euler(0, 270, 0);                 if (moveHorizontal.x > 0f) targetRot = Quaternion.Euler(0, 90, 0);                 headingLeft = !headingLeft;             }              //Adds character rotation when changing direction vertically             /*if(moveVertical.y < 0f && lookingUp || (moveVertical.y > 0f && !lookingUp))             {                 if (moveVertical.y > 0f) targetrot = Quaternion.Euler(0, 0, 0);                 if (moveVertical.y < 0f) targetrot = Quaternion.Euler(0, 180, 0);                 lookingUp = !lookingUp;             }*/              transform.rotation = Quaternion.Lerp(transform.rotation, targetRot, Time.deltaTime * 20f);              if (SceneManagement.insideHut)             {                 //Adds character rotation when changing direction horizontally, but snaps instead of fully rotating                 if (moveHorizontalSnap > 0)                 {                     transform.eulerAngles = new Vector2(0, 90);                 }                 else if (moveHorizontalSnap < 0)                 {                     transform.eulerAngles = new Vector2(0, -90);                 }                 //To possibly prevent diagonal movement with some control setups, try adding 'else if'                 //Adds character rotation when changing direction vertically, but snaps instead of fully rotating                 else if (moveVertical > 0)                 {                     transform.eulerAngles = new Vector2(0, 0);                 }                 //Use this to make the character face towards the camera.                 /*else if (moveVertical < 0)                 {                     transform.eulerAngles = new Vector3(0, 180);                 }*/             }              if (controller.isGrounded)             {                 if (allowJump)                 {                     moveDirection.y = -1f;                     //GetKeyDown will require the player to press the button each time they want to jump. GetKey will allow the player to spam the jump button if they keep pressing it down.                     if (Input.GetKeyDown(KeyCode.KeypadPlus) || Input.GetKeyDown("joystick button 0"))                     {                         moveDirection.y = jumpForce;                         jumped = true;                     }                     else if (!Input.GetKeyDown(KeyCode.KeypadPlus) || !Input.GetKeyDown("joystick button 0"))                     {                         jumped = false;                     }                 }                  if (allowCombat)                 {                     if (Input.GetKeyDown(KeyCode.Space) || Input.GetKeyDown("joystick button 7") || Input.GetKeyDown("joystick button 1"))                     {                         playerRenderer.material = textureChange;                         anim.SetTrigger("Attack");                     }                     else if (!Input.GetKeyDown(KeyCode.Space) || !Input.GetKeyDown("joystick button 7") || !Input.GetKeyDown("joystick button 1"))                     {                         playerRenderer.material = textureDefault;                     }                 }                 else if (!allowCombat)                 {                     playerRenderer.material = textureDefault;                 }                  if (allowInteract)                 {                     if (SceneManagement.xbox360Controller == 1)                     {                         if (Input.GetKeyDown("joystick button 2"))                         {                             anim.SetBool("Interact", controller.isGrounded);                             pickupWeapon.ObjectActivation();                             allowInteract = false;                         }                     }                     else if (SceneManagement.ps4Controller == 1)                     {                         if (Input.GetKeyDown("joystick button 0"))                         {                             anim.SetBool("Interact", controller.isGrounded);                             pickupWeapon.ObjectActivation();                             allowInteract = false;                         }                     }                     else                     {                         if (Input.GetKeyDown(KeyCode.Return))                         {                             anim.SetBool("Interact", controller.isGrounded);                             pickupWeapon.ObjectActivation();                             allowInteract = false;                         }                     }                 }                 if(openChest.allowOpen)                 {                     if (SceneManagement.xbox360Controller == 1)                     {                         if (Input.GetKeyDown("joystick button 2"))                         {                             anim.SetBool("Interact", controller.isGrounded);                             anim.SetTrigger("open");                             allowInteract = false;                         }                     }                     else if (SceneManagement.ps4Controller == 1)                     {                         if (Input.GetKeyDown("joystick button 0"))                         {                             anim.SetBool("Interact", controller.isGrounded);                             anim.SetTrigger("open");                             allowInteract = false;                         }                     }                     else                     {                         if (Input.GetKeyDown(KeyCode.Return))                         {                             anim.SetBool("Interact", controller.isGrounded);                             anim.SetTrigger("open");                             allowInteract = false;                         }                     }                 }             }         }         else         {             knockBackCounter -= Time.deltaTime;         }          moveDirection.y = moveDirection.y + (Physics.gravity.y * gravityScale * Time.deltaTime);          anim.SetBool("isGrounded", controller.isGrounded);         //If the character can't move, then the Speed is set to 0. Otherwise it'll use the horizontal input value.         anim.SetFloat("Speed",             !canMove             ? 0f             : Mathf.Abs(Input.GetAxis("Horizontal")));          //anim.SetFloat("Speed", Mathf.Abs(Input.GetAxis("Horizontal")));          /*if (interact)         {             if (Input.GetKeyDown(KeyCode.Return))             {                 anim.SetBool("Interact", controller.isGrounded);                 FindObjectOfType<Pickup>().ObjectActivation();                 interact = false;                 allowInteract = false;             }         }*/     }      public void Knockback(Vector3 direction)     {         knockBackCounter = knockBackTime;          moveDirection = direction * knockBackForce;         moveDirection.y = knockBackForce;     } }

enter image description here

19.04 settings not showing up in Unity Control Center

I am trying to turn on the touchpad while typing in my Ubuntu 19.04 computer, but in Unity Control Center only 3 icons show up. They are:

  1. Language Support
  2. Sharing
  3. Software and Updates

If I run as root, I get the first one, the last one, and Printers.

I looked for the touchpad while typing option in GNOME settings, but the setting isn’t there. How do I fix this, or turn on touchpad while typing?

Unity WebGL out of memory crash if load scene multiple times

When my game starts it loads a base scene, and then loads other secondary scenes on top of that base scene.

To load the secondary scene on top of the base scene, this is the code to load the scene additively

Code (CSharp):

            using (downloadWWW = new WWW(url)) {             yield return downloadWWW;                  if (downloadWWW.assetBundle != null) {                     GlobalData.assetBundle = downloadWWW.assetBundle;                     GlobalData.loadedBundleScene = "sceneName";                     SceneManager.LoadScene("sceneName", LoadSceneMode.Additive);                } 

Then later when i want to load another scene i remove the secondary scene like this

Code (CSharp):

SceneManager.UnloadScene("sceneName"); // same result using UnloadSceneAsync GlobalData.assetBundle.Unload(true); Resources.UnloadUnusedAssets(); 

(im really using UnloadSceneAsync, i just show UnloadScene to make it easier to read here)

This should have unloaded the secondary scene, then i call the top code again to load another scene on top of the base scene.

If it repeat this cycle 3 or 4 times the browser crashes with out of memory.

No crash in the editor, profiler shows the memory constant over multiple scene loads of the same scene (editor) while doing the same thing crashes in the browser.

Anybody knows what causes this?

Problem with Unity3D (Unity Remote) android devices

So I thought that maybe someone here might give me some tips on how to debug whats going on… As I dont know if this is android issue or not…

So Im using Unity3D and I need to test my games on android devices. Unity has 2 options for that: 1) build & run – which builds the project, copy the files onto the device and run, 2) Unity Remote – which lets user test their games without building the whole projects, very quick and extremely usefull.

Option 1 (build and run) always complains “Android device emulator-5554 offline”. So I adb kill-server and adb devices. Retry to build and it does what it was supposed to do.

Option 2 (Unity Remote) works ONLY ONCE per device. What I mean by that is I connect I new device, run Unity Remote (developer profile in the device, usb debbuging ON), then a message will pop up in the device (RSA key fingerprint, I let to remember the device). And when I press Play in Unity3D my game is working on the device I just set up. And It will continue to work as expected untill next reboot of the system (computer, not the device).

Once done that Unity Remote does not work anymore. The device is always there when I check with adb devices. I can still build and run the project. I tried to “Revoke USD debugging authorizations” on the device, but doesn’t help.

Creating a new HDRP example scene after upgrading Unity project

When a new game is templated using the HDRP template, there’s a nicely setup sample scene with post processing volume and many other settings.

I have noticed that Unity changes quite a lot in their HDRP sample projects from Unity version to Unity version.

I would like to keep up to date with what Unity recommends for HDRP settings. When I open my Unity 2018 project in Unity 2019, Unity upgrades my settings so that they still work, but their “new recommendations” are of course not incorporated.

And to my knowledge, I can not create a new HDRP sample scene in an existing Unity project.

Clicking “File” -> “New scene” creates a simplistic new scene, and all the special effect examples are missing, so this doesn’t create such a full-blown HDRP example scene.

I would like to be able to quickly copy new, recommended settings over the existing cameras, for example or to copy a PP volume over.

Is there a way to create a new HDRP example scene in an existing project?

Thank you.