Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Why does my code cause a warning

Discussion in 'Scripting' started by JoKrTheAbbreviation, Jun 26, 2019.

  1. JoKrTheAbbreviation

    JoKrTheAbbreviation

    Joined:
    Jun 26, 2019
    Posts:
    1
    Sorry now everyone for creating such a useless thread like this, but I'm a total beginner with Unity (I have completed the Roll a Ball -tutorial, wow!) and I have no idea why my code causes a warning and where the reason is. I'm going to tell a lot of useless information about my project because I'm not sure at all what information is useful.
    I have one scene, where I have a Main Camera, Directional Light, blue Plane (uses a material), a violet Sphere called player (uses a material, I have just renamed it from "Sphere" to "Player") which has a Spot Light as a child.
    The only script I run in this project right now is a component of the player. The player's components are:
    - Transform
    - Sphere (Mesh Filter)
    - Mesh Renderer
    - Sphere Collider
    - Player Controller (script)
    - Rigidbody (just for making the object dynamic, Is Kinematic is checked)
    - Character Controller
    Here's the only script:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class PlayerController : MonoBehaviour
    6. {
    7.  
    8.     public string[] controls;//w a s d
    9.     public float speed;
    10.     public float acceleration;
    11.     public float friction;
    12.     public int damage;
    13.     public int health;
    14.  
    15.     private float xspd;
    16.     private float zspd;
    17.     private CharacterController cc;
    18.  
    19.     void Start()
    20.     {
    21.         xspd = 0;
    22.         zspd = 0;
    23.         cc = GetComponent<CharacterController>();
    24.     }
    25.  
    26.     void Update()
    27.     {
    28.         //Movement
    29.         //get input
    30.         if (Input.GetKey(controls[0]) && (zspd < speed)) zspd += acceleration * Time.deltaTime;
    31.         if (Input.GetKey(controls[1]) && (xspd < -speed)) xspd -= acceleration * Time.deltaTime;
    32.         if (Input.GetKey(controls[2]) && (zspd > -speed)) zspd -= acceleration * Time.deltaTime;
    33.         if (Input.GetKey(controls[3]) && (xspd < speed)) xspd += acceleration * Time.deltaTime;
    34.         //friction
    35.         if ((zspd > 0) && !Input.GetKey(controls[0])) zspd -= friction * Time.deltaTime;
    36.         if ((zspd < 0) && !Input.GetKey(controls[2])) zspd += friction * Time.deltaTime;
    37.         if ((xspd > 0) && !Input.GetKey(controls[1])) xspd -= friction * Time.deltaTime;
    38.         if ((xspd < 0) && !Input.GetKey(controls[3])) xspd += friction * Time.deltaTime;
    39.  
    40.     }
    41. }
    And I know this code does not really affect any GameObject in the game by moving, scaling or rotating it, but it produces a warning and I want to fix it because it seems to also create a lag peak in the start of the game.
    Here's the warning:
    Internal: JobTempAlloc has allocations that are more than 4 frames old - this is not allowed and likely a leak
    I think this warning causes another warning:
    To Debug, enable the define: TLA_DEBUG_STACK_LEAK in ThreadsafeLinearAllocator.cpp. This will output the callstacks of the leaked allocations
    Edit: I commented and uncommented my code in order to find what causes the warnings and when I took the commenting (multiline, of course) away, there was no warning anymore. Still, if you have any idea of what caused this warning, please tell me. Please tell me too if I should delete this thread and if I should, how I should do it.
     
    Last edited: Jun 26, 2019
  2. SparrowGS

    SparrowGS

    Joined:
    Apr 6, 2017
    Posts:
    2,536
    Do you have any other imported assets?, what unity version are you on?

    You gotta start somewhere man (;
     
  3. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Going to make a guess the version has an "a" somewhere it it.
     
    SparrowGS likes this.
  4. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,294
    It's an internal error from systems you're not using, so it's a bug in Unity.

    As @Joe-Censored is hinting at, you might be using an alpha version of Unity - eg. 2019.3? The Hub is a piece of garbage, and one of it's many flaws is that it doesn't indicate properly which versions are ready for use.

    You can't delete threads on these forums.