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. Join us on Dec 8, 2022, between 7 am & 7 pm EST, in the DOTS Dev Blitz Day 2022 - Q&A forum, Discord, and Unity3D Subreddit to learn more about DOTS directly from the Unity Developers.
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

Python For Unity - Clear cached code

Discussion in 'Formats & External Tools Previews' started by mdooneymill, May 19, 2021.

  1. mdooneymill

    mdooneymill

    Joined:
    Feb 7, 2019
    Posts:
    9
    Hi,

    I've created a new PySide application based on the example provided with the package but I'm having issues with updated python code not being seen by the editor. I have to restart the editor in order to see the updated behaviour.
    Is this related to the way the QtApp lifecycle works and is there a way to force a refresh at all?

    Cheers,

    Mark
     
  2. mdooneymill

    mdooneymill

    Joined:
    Feb 7, 2019
    Posts:
    9
    found a way.
    I was using importlib to reload my python but missed the QApplication instance bits.

    Code (CSharp):
    1.  
    2. # coding: utf-8
    3. import sys
    4. from PySide2.QtCore import Qt
    5. from PySide2.QtWidgets import QApplication, QLabel
    6. def popup():
    7.     app = QApplication.instance()
    8.     if app is None:
    9.         app = QApplication(sys.argv)
    10.     label = QLabel("Hello World", alignment=Qt.AlignCenter)
    11.     label.show()
    12.     sys.exit(app.exec_())
    13.  
     
    SensitiveCube likes this.