Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice

Resolved Blend tree not working after game build

Discussion in 'Animation' started by AssassinParpar, Dec 23, 2023.

  1. AssassinParpar

    AssassinParpar

    Joined:
    Nov 27, 2020
    Posts:
    3
    Hi, I work on a 2D game that includes guns and I built the aim mechanic with a blend tree, which calculates my mouse positions, gets the angle and the blend tree does the rest.
    Recently I noticed that in one of my builds (The problem occurs only in the build version of the game, in the Unity editor it works just fine), one particular gun - the pistol, isn't working.
    After some debugging, I understood that the problem is that the blend tree itself doesn't activate (even though it does work fine in the editor and all the other guns(that are also based on a blend tree) work well after the build).
    I have no idea what it could be, hope someone can help me.
    I've worked on the game for about 2 years now and I would say that I'm a bit experienced but I never saw anything like that(maybe I'm just going a bit deeper in the engine to find problems xd).

    Here is the code that controls the blend tree positions (but I'm pretty sure that the problem is with the blend tree and not the code):

    Code (CSharp):
    1.    void Update()
    2.    {
    3.        moveX = Input.GetAxis("Horizontal");
    4.  
    5.      
    6.  
    7.        if ((WeaponManager.instance.pistol && gameObject.name == "PLAYER") || (WeaponManager.instance.pistol1 && gameObject.name == "PLAYER 1"))
    8.        {
    9.            if (Mathf.Abs(moveX)<0.1)
    10.            {
    11.                animator.SetBool("Shutgun", false);
    12.                animator.SetBool("Machine", false);
    13.                animator.SetBool("Pistol", true);
    14.            }
    15.            else
    16.            {
    17.                animator.SetBool("Pistol", false);
    18.            }
    19.        }
    20.        else
    21.        {
    22.            animator.SetBool("Pistol", false);
    23.        }
    24.  
    25.        var point = cam.ScreenToWorldPoint(Input.mousePosition);
    26.  
    27.        if (PlayerController.instance.ifLooksRight)
    28.        {
    29.            var x = point.x - transform.position.x;
    30.            var y = point.y - transform.position.y;
    31.  
    32.            animator.SetFloat("x", x);
    33.            animator.SetFloat("y", y);
    34.        }
    35.        else
    36.        {
    37.  
    38.            var x = point.x - transform.position.x;
    39.            var y = point.y - transform.position.y;
    40.  
    41.  
    42.            animator.SetFloat("x", Mathf.Abs(x));
    43.            animator.SetFloat("y", y);
    44.        }
    45.    }
    Thanks for any feedback in advance, I appreciate every word
     
  2. sergiusz308

    sergiusz308

    Joined:
    Aug 23, 2016
    Posts:
    235
    I'd suggest to connect debugger (VS) to the build and investigate what's happening.
     
  3. AssassinParpar

    AssassinParpar

    Joined:
    Nov 27, 2020
    Posts:
    3
    Thank you for your response, I appreciate it.
    I solved it after finding that another part of the code controlled it too. actually I'm not really sure how it worked in the editor itself xd
     
  4. sergiusz308

    sergiusz308

    Joined:
    Aug 23, 2016
    Posts:
    235
    Glad you solved it - that kind is like a 99% of "works in editor, fails in build" situations.

    I'm first to blame unity but you gotta admit that build system they put together is very reliable, in that regard. Nowhere near to Unreal cooks and all random problems it can cause, esp. in mature, complex projects.
     
  5. AssassinParpar

    AssassinParpar

    Joined:
    Nov 27, 2020
    Posts:
    3

    You are absolutely right, it was just something I had never encountered and it took so much time compared to the other problems I had so it was like the last leap