Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    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.