Comments (13)
Hi, the patch to 'write' arrays in in my queue. I will push it tomorrow with the new features
from unrealenginepython.
@LarsGroh arrays writing is now avaialble. Remember you can do
my_asset.Materials = [new_material]
instead of directly calling set_property()
from unrealenginepython.
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.
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.
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.
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.
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.
@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.
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.
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.
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.
Btw, have you tried if
mat = ue.load_object(Material, '/Game/Materials/my_test_material')
works for you ?
from unrealenginepython.
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)
- upgrade python console to IPython or other alternatives?
- Error with module h5py
- 4.26.2 Python 3.7 Crash When call bind_event in uep HOT 2
- How to add force to pyactor HOT 1
- keyboard input HOT 2
- Where are the python modules? HOT 1
- Build Failed: Cannot open include file 'UEPyModule.h'
- seems not work at 4.27?
- How can I redirect a python class so that the engine can recognize him?(请问如何重定向一个python类,然后引擎能够识别他?)
- Spawn a pyactor in begin_play doesn't works fine.
- First demo in docs/Http_API.md cause the editor crashed in 4.27.2
- Great content! It might be possible to create an updated version (ue5) HOT 1
- How to call Python automation code from a UI button? HOT 4
- How do I get text from a UEditableTextBox?
- How to run a simple python function, with inputs & outputs, from blueprints? HOT 5
- I am using multithreading to Spawn a Blueprint Actor and Unreal Engine is crashing suddenly when the spawn function gets called.
- consider archiving the repo in github
- how can I change my python env in my own source(python3.8),rather then the give source(python3.6 in UnrealEnginePython/)
- a
- Issues about the HouseKeeper
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from unrealenginepython.