Giter Site home page Giter Site logo

Comments (13)

rdeioris avatar rdeioris commented on July 22, 2024

Hi, the patch to 'write' arrays in in my queue. I will push it tomorrow with the new features

from unrealenginepython.

rdeioris avatar rdeioris commented on July 22, 2024

@LarsGroh arrays writing is now avaialble. Remember you can do

my_asset.Materials = [new_material]

instead of directly calling set_property()

from unrealenginepython.

LarsGroh avatar LarsGroh commented on July 22, 2024

Hi,
Thanks a lot. I've tried it out.. this works:

import unreal_engine as ue
ue.get_selected_assets()[0]""
# selecting the skeletal mesh manually in the content browser
a = ue.get_selected_assets()[0]
# selecting the material manually in the content browser
m = ue.get_selected_assets()[0]
materials = a.Materials
materials[0] = m
a.Materials = materials

But this approach causes the editor to crash:

def find_object(path):
    object_ = None
    try:
        object_ = ue.find_object(path)
        return object_
    except:
        pass
    finally:
        return object_

def relink_materials(asset, materials_folders):

    new_mats = []
    for material in asset.Materials:
        mat_name = material.get_name()

        supposed_path = "%s/%s" % (materials_folders, mat_name)
        ue.log("Looking for this material: %s" % supposed_path)
        supposed_material = find_object(supposed_path)

        if supposed_material:
            ue.log("Found supposed material and assigning it: %s" % supposed_path)
            new_mats.append(supposed_material)
        else:
            new_mats.append(material)

    if new_mats:
        asset.Materials = new_mats

    return new_mats


relink_materials(a, "/Games/Content/Materials")

The respective materials in the "Materials"-folder are being found and assigned to the list "new_mats".
But when I navigate into the content folder browser Unreal crashes when it tries to reload the Material thumbnails.

Any suggestions?

from unrealenginepython.

rdeioris avatar rdeioris commented on July 22, 2024

can you pull latest code ? I have tried to reproduce your problem but your script works flawlessly. Are you using python 2 or 3 ?

from unrealenginepython.

LarsGroh avatar LarsGroh commented on July 22, 2024

Hi,
I pulled the latest code. I am using python 3.
The error still occurs. But I figured out why:

"ue.find_object" returns an instance of type "Pakage" and not of type "Material".
This causes Unreal to crash - how do I retrieve an instance of the acutal type?

Another strange thing was, that "find_object" only returns an instance, when another instance of the object/asset has already been instanciated before - e.g. by calling ue.get_selected_assets() on it.
Is there some initializiation that needs to be executed for all content browser assets to be "available"?

Here is my output:

>>> m = ue.find_object("/Game/Materials/my_test_material")
unable to find object /Game/Materials/my_test_material
Traceback (most recent call last):
  File "<string>", line 1, in <module>
Exception: unable to find object /Game/Materials/my_test_material

# with my_test_material selected:
>>> m = ue.get_selected_assets()[0]
>>> ue.log(m)
<unreal_engine.UObject 'my_test_material' (0x00000000488150C0) UClass 'Material'>
>>> m = ue.find_object("/Game/Materials/my_test_material")
>>> ue.log(m)
<unreal_engine.UObject '/Game/Materials/my_test_material' (0x0000000035C94B80) UClass 'Package'>

from unrealenginepython.

LarsGroh avatar LarsGroh commented on July 22, 2024

Ok..I dug around a bit and seems I have missed the difference between loaded and unloaded objects.
"ue.load_object(Material, "MY_PATH") does what I need.

But what's the actuall use-case for "find_object" then?

from unrealenginepython.

rdeioris avatar rdeioris commented on July 22, 2024

Hi, as you have already spotted, find_object is only meaningful when an object is already loaded in memory. It is basically an optimization. More infos here:

https://docs.unrealengine.com/latest/INT/Programming/Assets/ReferencingAssets/

(Find/Load Object section)

What i need to understand is why the editor crashes. The property system should warn you when you try to inject the wrong type. I will investigate on it. Thanks

from unrealenginepython.

rdeioris avatar rdeioris commented on July 22, 2024

@LarsGroh ok i have managed to reproduce the crash. Basically when creating arrays the type-safety is not correctly checked. Expect a patch soon. I will close the ticket once the error is fixed.

from unrealenginepython.

rdeioris avatar rdeioris commented on July 22, 2024

The crash problem should be fixed now. Regarding your specific problem with find_object:

 m = ue.find_object("/Game/Materials/my_test_material")

refers to a UPackage.

while

 m = ue.find_object("my_test_material")

refers to the Material.

You can Eventually be more strict and use:

 m = ue.load_object(Material, "/Game/Materials/my_test_material")

(the first parameters ensures the to load the object of the specified type)

from unrealenginepython.

LarsGroh avatar LarsGroh commented on July 22, 2024

Hey,
thank you some much for your effort and support!!!
This Plugin is going to improve our efficiency by far!

Concerning ue.find_object:

Shouldn't the return value be the same regardless the path specification?
In my case, I don't acutally know what a UPackage is - but that's my problem and I need to look it up.
But isn't it confusing to get different types with essentially the same method - especially when supplying the more specific full path?
In my case using the short name is not suitable as I have several Materials with the same name in different folders.

But based on this fact - is there a way to get the Material reference through UPackage - is this again something I would find in the UE4 docs?

from unrealenginepython.

rdeioris avatar rdeioris commented on July 22, 2024

Unfortunately this is how the unreal api works :( (they are two different objects for unreal) But i totally agree, consistence is really important. I will check how to improve it

from unrealenginepython.

rdeioris avatar rdeioris commented on July 22, 2024

Btw, have you tried if

mat = ue.load_object(Material, '/Game/Materials/my_test_material')

works for you ?

from unrealenginepython.

LarsGroh avatar LarsGroh commented on July 22, 2024

Alright, then I guess I just need to get more into the unreal api itself.
Yes, ue.load_object works for me just fine!

Thanks!!

from unrealenginepython.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.