I wrote a Python script (for the editor) to attach a mesh to a scene component of an actor (vegetation_root_component).
- In the logs everything looks fine, but no mesh appears added to the actor
- If I move the actor in the scene, it disappears, not a good sign
root_transform = vegetation_root_component.get_world_transform() # Transform world location to local local_location = root_transform.inverse_transform_location(hit_location) local_rotation = root_transform.inverse_transform_rotation(unreal.Rotator(0,0,0)) # Make a transform for the mesh rel_transform = unreal.Transform(location=local_location, rotation=local_rotation, scale=unreal.Vector(1,1,1)) # Add a new StaticMeshComponent to the actor sm_component = unreal.StaticMeshComponent(actor) sm_component.set_relative_transform(rel_transform,sweep=False, teleport=True) # Set static mesh sm_component.set_static_mesh(random_mesh) # Attach to vegetation root attached = sm_component.attach_to_component( vegetation_root_component, socket_name="", location_rule=unreal.AttachmentRule.KEEP_RELATIVE, rotation_rule=unreal.AttachmentRule.KEEP_RELATIVE, scale_rule=unreal.AttachmentRule.KEEP_RELATIVE, weld_simulated_bodies=True ) notes:
attachedisTruehit_locationis a line trace result. It appears on the mesh with a debug sphere.
LogPython: blocking_hit=True LogPython: hit_location=<Struct 'Vector' (0x000002762A062B30) {x: -24.369755, y: -278.251794, z: 136.546713}> LogPython: hit_actor=<Object '/Game/VRTemplate/Maps/VRTemplateMap.VRTemplateMap:PersistentLevel.Tree_Actor_C_2' (0x0000045B51E21400) Class 'Tree_Actor_C'> LogPython: impact_normal=<Struct 'Vector' (0x000002762A0629A0) {x: -0.936350, y: 0.315688, z: -0.153591}> LogPython: Hit: Tree_Actor_C_2 at <Struct 'Vector' (0x000002762A062B30) {x: -24.369755, y: -278.251794, z: 136.546713}> LogPython: Random mesh: shrub_04_b_LOD0 LogPython: Added mesh component 'shrub_04_b_LOD0' to Tree_Actor_C_2