-
-
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() |
Ok so it seems if you run this in your startup they will persist, pretty much as the documentation promised for startup objects
import unreal
@unreal.uclass()
class OnAssetImports(unreal.EditorUtilityObject):
@unreal.ufunction(static=True, params=[unreal.Factory, unreal.Object], meta=dict(BlueprintEvent=True))
def log_import_name(factory, created_object):
print("Hello %s" % created_object.get_name())
import_subsytem = unreal.get_editor_subsystem(unreal.ImportSubsystem)
import_subsytem.on_asset_post_import.add_callable(
OnAssetImports.log_import_name
)
saving this to init_unreal.py inside your Content/Python folder should work
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
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.
Not really the forum for this, but try looking at scoped slow tasks
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.
hahahahhah,ok.it's my fault to misunderstand what your talk.
i may get it.Thank you to answer my question,Have a nice day.
(my first time to say somthing in git , amazing and learn something from your git, Thank you. (^ .^) )