Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Feature Request Optimization suggestion: Delay the initialization of Python Scripting until it is first called

Discussion in 'Formats & External Tools Previews' started by SolarianZ, Sep 26, 2023.

  1. SolarianZ

    SolarianZ

    Joined:
    Jun 13, 2017
    Posts:
    222
    Currently, every time the code is modified or entering Play Mode, Python Scripting is re-initialized, which significantly slows down the responsiveness of the Editor.

    Can we delay the initialization of Python Scripting until it is first called?

    upload_2023-9-26_10-37-36.png

    (Additionally, Visual Scripting also has this issue.)
     
  2. guoxx_

    guoxx_

    Joined:
    Mar 16, 2021
    Posts:
    55
    We encountered the same issue that make Python less practical during development. Can we have an option to disable this initialization process for each code compilation?
     
  3. SolarianZ

    SolarianZ

    Joined:
    Jun 13, 2017
    Posts:
    222
    [SOLVED] I have reviewed the code for PythonRunner version 7.0.1 and found that you can simply comment out the
    PythonRunner.InitializeOnLoad
    method. It has already implemented initialization checking internally, so if it is called before initialization, it will automatically call the initialize method.

    upload_2024-2-5_16-39-20.png
     
  4. SolarianZ

    SolarianZ

    Joined:
    Jun 13, 2017
    Posts:
    222
    After making the aforementioned modifications, the Editor may become unresponsive for a few seconds when executing Python code for the first time. Therefore, I have added a progress bar to provide a visual indication.

    upload_2024-2-5_16-47-50.png
     
  5. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,268
    Throw that ClearProgressBar into a finally, then you don't have to repeat it twice :p
     
    SolarianZ likes this.