Skip to content

Instantly share code, notes, and snippets.

@rondreas
Created February 14, 2021 20:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rondreas/d251aeee36ff1b371d747359433005e6 to your computer and use it in GitHub Desktop.
Save rondreas/d251aeee36ff1b371d747359433005e6 to your computer and use it in GitHub Desktop.
import unreal
@unreal.uclass()
class OnAssetPostImportAction(unreal.EditorUtilityObject):
@unreal.ufunction(override=True)
def run(self):
""" Add a callable static function to be called whenever an asset is
imported.
"""
# Get the Import Subsystem,
import_subsytem = unreal.get_editor_subsystem(unreal.ImportSubsystem)
# Add a callable to the OnAssetPostImport delegate,
import_subsytem.on_asset_post_import.add_callable(
OnAssetPostImportAction.log_import_name
)
@unreal.ufunction(static=True, params=[unreal.Factory, unreal.Object], meta=dict(BlueprintEvent=True))
def log_import_name(factory, created_object):
""" Static function that should print asset name whenever a new asset is
imported.
:param factory: the factory class used for import
:type factory: unreal.Factory
:param created_object: the imported asset,
:type created_object: unreal.Object
"""
print("Hello %s" % created_object.get_name())
def main():
# Execute the run function for our Editor Utility Object,
OnAssetPostImportAction().run()
if __name__ == '__main__':
main()
@RyanHz2
Copy link

RyanHz2 commented Jun 7, 2021

Oh,myGodness.Thank you sosososososososo much. it solve my “Headache” problem,
but if i can , can i know why it can run . it look just reverve the code , but it make me learn a lot , Thank you
(Sorry for reply your message after two days , beacause i go another place without computer , Sorry)
Ps. i am your fans now , hahah

@RyanHz2
Copy link

RyanHz2 commented Jul 1, 2021

hello, Mr.rondreas. during this time, i learn and do something unreal plugins with python in my relaxlife, is so wonderfull.
but now, i have a question : some python codes start by our clicked and will run for a longtime, but now i dont want it run a long time , iwant to stop it by my exe , as i want to start/stop python code by myself.
is it can do ? Do you have some suggestions?
Thank you for your help , and sorry to occupy your time.

@rondreas
Copy link
Author

rondreas commented Jul 1, 2021

Not really the forum for this, but try looking at scoped slow tasks

@RyanHz2
Copy link

RyanHz2 commented Jul 1, 2021

i know the scoped slow tasks, but i mean
like this forum "StartupObjects/index.html" what we talk ,
if it run ,it will run a long time to "print("Hello %s" % created_object.get_name())" when i import some assets
but with UE running, i want it stop, stop this code running, back to the time i can import assets without this code by my thought
it is the question i think a lot ,when i keep develop this forum.
Sorry to occupy your time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment