Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Why my leantween animation works in Unity editor but not on my Android device

Discussion in 'Editor & General Support' started by Chethan007, May 30, 2022.

  1. Chethan007

    Chethan007

    Joined:
    Dec 3, 2020
    Posts:
    51
    I have created a multi-player game. After the game gets over I am loading the game over scene.The leantween animation works perfectly fine in the Unity editor but when it comes to my android device it doesn't work only. I really can't understand why.

    Here is my code


    Code (CSharp):
    1. public class GameOverManagerMP : MonoBehaviourPunCallbacks
    2.    {
    3.        // Start is called before the first frame update
    4.  
    5.        [SerializeField]private GameObject GameOverImage;
    6.        [SerializeField]private GameObject Mylife;
    7.        [SerializeField]private GameObject OpponentLife;
    8.        [SerializeField]private GameObject Result;
    9.        [SerializeField]private GameObject NetworkMessage;
    10.        [SerializeField]private GameObject HomeButton;
    11.        [SerializeField]private GameObject ShareButton;
    12.  
    13.        private float time = 0.9f;
    14.      
    15.        private void Awake()
    16.        {
    17.            Mylife.GetComponent<Text>().text = "My life : " + MultiPlayerScoreManager.instance.MyLifeCounter.ToString();
    18.            OpponentLife.GetComponent<Text>().text = "Opponent life : " + MultiPlayerScoreManager.instance.OpponentLifeCounter.ToString();
    19.            NetworkMessage.GetComponent<Text>().text = MultiPlayerScoreManager.instance.NetworkDisconnectedMessage;
    20.            Result.GetComponent<Text>().text = MultiPlayerScoreManager.instance.FinalResult;
    21.        }
    22.  
    23.        // public static Action DisconnectFromPhotonNetwork = delegate { };
    24.        void Start()
    25.        {
    26.            SFXManager.PlaySound("whoosh");
    27.            MoveGameOverElements();    
    28.        }
    29.  
    30.        private void MoveGameOverElements()
    31.        {
    32. Debug.Log("Game Over Move Elements.................");
    33.           GameOverImage.transform.LeanMoveLocal(new Vector2(0, 689f), time).setEaseOutQuad();
    34.            Mylife.GetComponent<Text>().transform.LeanMoveLocal(new Vector2(-178f, 366f), time).setEaseOutQuad();
    35.            OpponentLife.transform.LeanMoveLocal(new Vector2(-423f, 272f), time).setEaseOutQuad();
    36.            LeanTween.scale(Result, Vector3.zero, 0f);
    37.            LeanTween.scale(Result, new Vector3(1, 1, 1), 0.3f).setEase(LeanTweenType.easeInCubic);
    38.            NetworkMessage.transform.LeanMoveLocal(new Vector2(-178f, -216f), time).setEaseOutQuad();
    39.            HomeButton.transform.LeanMoveLocal(new Vector2(-216f, -609f), time).setEaseOutQuad();
    40.            ShareButton.transform.LeanMoveLocal(new Vector2(157f, -609f), time).setEaseOutQuad();
    41.        }
    42.    }
    The result text only has been given the scale 0 to scale 1 , a pop out like animation. I even commented the line where Time.timeScale=0; after the game got over in the previous scene, but there is no use as such. All the other elements either move to the left, right,top or bottom.

    This is the screenshot of my Unity editor while it is not in Play mode :



    Here is the screenshot of my Unity editor in Play mode:

    Screenshot of the mobile(android) device. You can see in the bottom a little of the button is there on the screen

    My aim to bring a fluid like animation into play when the game gets over

     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,713
    Some candidate ideas:

    - there may be a device-only error happening (check the logs)

    - it might be working but ambiguously mis-layered and the layers sort slightly different on device (if using sprites)

    - it might be working but mis-anchored / mis-scaled (if using UI)

    - some other timing issue might be at play (A script that depends on another running first)

    Whatever it is, here is an approach to figure out what's going on:

    You must find a way to get the information you need in order to reason about what the problem is.

    What is often happening in these cases is one of the following:

    - the code you think is executing is not actually executing at all
    - the code is executing far EARLIER or LATER than you think
    - the code is executing far LESS OFTEN than you think
    - the code is executing far MORE OFTEN than you think
    - the code is executing on another GameObject than you think it is
    - you're getting an error or warning and you haven't noticed it in the console window

    To help gain more insight into your problem, I recommend liberally sprinkling Debug.Log() statements through your code to display information in realtime.

    Doing this should help you answer these types of questions:

    - is this code even running? which parts are running? how often does it run? what order does it run in?
    - what are the values of the variables involved? Are they initialized? Are the values reasonable?
    - are you meeting ALL the requirements to receive callbacks such as triggers / colliders (review the documentation)

    Knowing this information will help you reason about the behavior you are seeing.

    If your problem would benefit from in-scene or in-game visualization, Debug.DrawRay() or Debug.DrawLine() can help you visualize things like rays (used in raycasting) or distances.

    You can also call Debug.Break() to pause the Editor when certain interesting pieces of code run, and then study the scene manually, looking for all the parts, where they are, what scripts are on them, etc.

    You can also call GameObject.CreatePrimitive() to emplace debug-marker-ish objects in the scene at runtime.

    You could also just display various important quantities in UI Text elements to watch them change as you play the game.

    If you are running a mobile device you can also view the console output. Google for how on your particular mobile target, such as this answer or iOS: https://forum.unity.com/threads/how-to-capturing-device-logs-on-ios.529920/ or this answer for Android: https://forum.unity.com/threads/how-to-capturing-device-logs-on-android.528680/

    Another useful approach is to temporarily strip out everything besides what is necessary to prove your issue. This can simplify and isolate compounding effects of other items in your scene or prefab.

    Here's an example of putting in a laser-focused Debug.Log() and how that can save you a TON of time wallowing around speculating what might be going wrong:

    https://forum.unity.com/threads/coroutine-missing-hint-and-error.1103197/#post-7100494

    If it is layering:

    Three (3) ways that Unity draws / stacks / sorts / layers / overlays stuff:

    https://forum.unity.com/threads/orthographic-camera-rendering-order.1114078/#post-7167037

    In short,

    1. The default 3D Renderers draw stuff according to Z depth - distance from camera.

    2. SpriteRenderers draw according to their Sorting Layer and Sorting Depth properties

    3. UI Canvas Renderers draw in linear transform sequence, like a stack of papers

    If you find that you need to mix and match items using these different ways of rendering, and have them appear in ways they are not initially designed for, you need to:

    - identify what you are using
    - search online for the combination of things you are doing and how to to achieve what you want.

    There may be more than one solution to try.

    Additional reading in the official docs:

    https://docs.unity3d.com/Manual/2DSorting.html

    Finally, here are some notes on UI Anchoring, Scaling, CanvasScaler, etc:

    https://forum.unity.com/threads/inc...size-between-two-people.1130146/#post-7261747

    https://forum.unity.com/threads/game-ui-button-size-problem.1142650/#post-7337383
     
  3. Chethan007

    Chethan007

    Joined:
    Dec 3, 2020
    Posts:
    51
    Thanks for such a detailed reply and sorry for the late reply. I did follow ur instructions and was able to solve the issue but still left with a question actually. But before that for those who are reading this I will tell you what I did

    So my issue was in the Unity editor things were fine but in the android device it was a problem. So I sprinkled Debug.Log() statement everywhere and checked for my android device log as per the above link i.e., here and I found that I my code for the line

    Code (CSharp):
    1.  SFXManager.PlaySound("whoosh");
    some null reference error was coming. I simply removed that line and it is working fine now.

    But the point is why is that line causing an error in the first place itself when it can work fine in the unity editor as such?