Skip to content

extract_uasset

ExtractUAsset

Bases: Extractor

Extract a UAsset.

Source code in client/ayon_unreal/plugins/publish/extract_uasset.py
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
class ExtractUAsset(publish.Extractor):
    """Extract a UAsset."""

    label = "Extract UAsset"
    hosts = ["unreal"]
    families = ["uasset", "umap"]
    optional = True

    def process(self, instance):
        extension = (
            "umap" if "umap" in instance.data.get("families") else "uasset")
        ar = unreal.AssetRegistryHelpers.get_asset_registry()

        self.log.debug("Performing extraction..")
        staging_dir = self.staging_dir(instance)

        members = instance.data.get("members", [])

        if not members:
            raise RuntimeError("No members found in instance.")

        # UAsset publishing supports only one member
        obj = members[0]

        asset = ar.get_asset_by_object_path(obj).get_asset()
        sys_path = unreal.SystemLibrary.get_system_path(asset)
        filename = Path(sys_path).name

        shutil.copy(sys_path, staging_dir)

        self.log.info(f"instance.data: {instance.data}")

        if "representations" not in instance.data:
            instance.data["representations"] = []

        representation = {
            "name": extension,
            "ext": extension,
            "files": filename,
            "stagingDir": staging_dir,
        }
        instance.data["representations"].append(representation)