Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Resolved A very noob question about a console message

Discussion in 'Getting Started' started by Peeter1978, Apr 5, 2021.

  1. Peeter1978


    Mar 29, 2021
    So, I'm doing the Junior Programmer thing on Unity Learn and building a very primitive little game on Unity version 2018.4.33f1 as part of it. It's a sideways thing where player has to dodge flying balls. It runs exactly as intended but now I get the following console message:

    InvalidOperationException: EnsureRunningOnMainThread can only be called from the main thread
    UnityEngine.Object.EnsureRunningOnMainThread () (at C:/buildslave/unity/build/Runtime/Export/UnityEngineObject.bindings.cs:153)

    I think it has something to do with the particle system because before adding those there was no error message. Any advice?
    Here the PlayerController code:

    Code (csharp):
    1.  using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. public class PlayerController : MonoBehaviour
    5. {
    6.     public float verticalInput;
    7.     public float speed = 10.0f;
    8.     public ParticleSystem EnergyExplosion;
    9.     public ParticleSystem DustExplosion;
    11.     // Start is called before the first frame update
    12.     void Start()
    13.     {
    14.     }
    15.     // Update is called once per frame
    16.     void Update()
    17.     {
    18.         verticalInput = Input.GetAxis("Vertical");
    19.         transform.Translate(Vector3.up * verticalInput * Time.deltaTime * speed);
    20.     }
    21.     private void OnTriggerEnter(Collider other)
    22.     {
    23.         if (other.gameObject.layer == 12)
    24.         {
    25.             Debug.Log("GAME OVER!");
    26.             DustExplosion.Play();
    27.             Destroy(gameObject);
    28.         }
    29.         else if (other.gameObject.layer == 11)
    30.         {
    31.             EnergyExplosion.Play();
    32.             Destroy(other.gameObject);
    33.         }
    34.     }
    35. }
    Last edited: Apr 9, 2021
  2. Peeter1978


    Mar 29, 2021
    Hm. I think I found the answer - it something I'd call a glitch, as people have had it before and apparently it has something to do with the animation window being open, not with an actual error in the code. Anyhow - I have now been tinkering on my game, changed things a lot and this particular error message went as mysteriously as it came. I don't have this problem anymore. Instead I have other, bigger ones. :D But these I leave for another post.
    Joe-Censored likes this.
  3. Vryken


    Jan 23, 2018
    Yeah, in these instances, these warnings/errors are coming from the built-in Unity components. You'll have to get used to seeing them appear in the console, as they're pretty common.

    A key thing to look for in any error messages is the name of the script file. The error you've posted states that it's in the following file:

    As long as you know that this is not one of your scripts, you can usually ignore it (unless it's from an asset instead).
    Joe-Censored and Peeter1978 like this.