20tab / UnrealEnginePython

Embed Python in Unreal Engine 4
MIT License
2.74k stars 743 forks source link

Get reference to component in blueprint asset #457

Closed tweaq closed 6 years ago

tweaq commented 6 years ago

First off: is there a list of commands? I think I could figure some stuff out if I could just search through a list.

Anyway, now I'm just trying to change the static mesh in a child blueprint. I have my script creating the child blueprint in the content browser and I can create a new staticmesh component inside of it (using this link) But I would rather just set the mesh that is in there. I can't seem to get a reference to the component. I mostly just can't figure out what commands to use.

rdeioris commented 6 years ago

Hi, if you mean the list of wrappers, you find it here: https://github.com/20tab/UnrealEnginePython/blob/master/Source/UnrealEnginePython/Private/UEPyModule.cpp#L198

but take into account that those are mostly optimizations, and instead, 99% of time you will use the reflection api. I suggest you to read this one:

https://github.com/20tab/UnrealEnginePython/blob/master/tutorials/YourFirstAutomatedPipeline.md

your specific case:

https://github.com/20tab/UnrealEnginePython/blob/master/tutorials/YourFirstAutomatedPipeline.md#put-it-all-in-a-new-blueprint

tweaq commented 6 years ago

Will do. Thank you very much. I'm an animator, fumbling through trying to code, so a lot of it is over my head (at least for now). But that looks promising.

tweaq commented 6 years ago

using : ue.log(bp.SimpleConstructionScript.DefaultSceneRootNode.ChildNodes[0].ComponentTemplate.StaticMesh)

It seems I am unable to get a reference to (or be able to set) the Static Mesh in a child blueprint. It works fine on the parent blueprint though.

rdeioris commented 6 years ago

Hi, i think you want UserConstructionScript (the tab Construction Script in blueprint) that is available in bp.FunctionGraphs array and you can manipulate as a normal graph

rdeioris commented 6 years ago

Sorry again, i think you were not referring to the constrction script but instead you want defaults for you blueprint. In such a case you need to edit the cdo (class default object):

bp.GeneratedClass.get_cdo().CapsuleComponent.CapsuleRadius = 300

tweaq commented 6 years ago

I tried using the cdo, but that didn't work either. Its an actor blueprint with a static mesh. i tried it with the static mesh as the root and under a default scene root

I tried the exact same thing but just changing the original blueprint for the child blueprint. I get IndexError: list index out of range when trying to set the mesh with bp_child.SimpleConstructionScript.DefaultSceneRootNode.ChildNodes[0].ComponentTemplate.StaticMesh = sphere It works find for the original blueprint, it seems to hate the Child Blueprint Class. I think i'm going to try the work around of just creating the nodes in the construction script.

rdeioris commented 6 years ago

I fear i am not understanding your issue. Can you post a couple of screenshots with the situation you have now and the one you want ? Thanks

tweaq commented 6 years ago

capture capture2

def createBP(medidroot, MedItem):
    bppath = medidroot + '/Blueprints/BP_' + MedItem
    #creates child bp from MedItem class
    bp_child = ue.create_blueprint(BP_MedItem_C, bppath)
    return bp_child     

def setStaticMesh(bp_child, model):
    #set imported mesh to child bp_child
    bp_child.GeneratedClass.get_cdo().NewMesh = model

This is what I have ended up with. This does work. But I feel it would be better to set the StaticMesh directly, in the child blueprint, instead of changing the variable in the construction script. I wasn't able to get a reference to the child blueprint's static mesh.

So if nothing else, I can just close this and be done with it. Thanks for all the help.

rdeioris commented 6 years ago

Hi, yes it is better to directly set the skeletalmesh of the child (or parent) blueprint:

bp.GeneratedClass.get_cdo().Mesh.SkeletalMesh = <skeletal_mesh_object>
tweaq commented 6 years ago

It's a static mesh, but no matter what I try it says "NoneType object has no attribute 'SkeletalMesh' , or I tried StaticMesh.

rdeioris commented 6 years ago

That's because you have to respect the name of the component, if it is not called 'Mesh', you need to adapt the code (I suppose it is called NewMesh)

tweaq commented 6 years ago

It should be StaticMesh, that is what the static mesh is named under the DefaultSceneRoot. I was trying to set the static mesh in there, instead of having to use the variable in the construction script.

It seems to not like StaticMeshes. I tried the example from the Kaiju: creating a character blueprint and setting the setting the capsule and moving the mesh. That works fine on the capsule and skeletal mesh, but when I add a static mesh to the blueprint, it always comes back as "'NoneType' object has no attribute RelativeLocation"