Adding mesh to Actor


#1

I’d like to instantiate a StaticMeshComponent attached to an actor at a certain relative position. (determined programmatically) However I couldn’t find an equivalent to Actor.spawn_at_xform for components, so I don’t know how to do that.

Thanks for your help.


#2

Hi - here is some example code that works in SkookumDemo. It grabs a mesh from one of the cubes, and attaches it to the hero mannequin so it hovers above it:

!cube : @'SM_DemoCube_2'
!cube_mesh_component : cube.component_by_class(StaticMeshComponent.static_class)<>StaticMeshComponent
!mesh : cube_mesh_component.@static_mesh
!hero : Hero.instances_first
!new_component : StaticMeshComponent!new(hero "MyComponent".Name)
new_component.register_component
new_component.attach_to(hero.root_component)
new_component.static_mesh_set(mesh)
new_component.relative_location_set(Vector3!xyz(0 0 Real.@@meter))

Let me know if this works for you and if it solves your problem!


#3

It works, thank you!