Download

Easy parenting in Python... not easy

Ok I have banged my head long enough. This is the easiest thing to do in most programs. Parenting one mesh to another or in Unreals case one Actor to another.
Goal: I want to animate a ton of cubs with maya or c4d then bring them in and add trees to every cube and parent them to the cubes so they move around (parented to the cubes)

I set this up but i get all kinds of error in the “attach_to_actor” it wants an actor and I am giving it one. I am not sure what I am doing wrong. How do you call and actor?

import unreal

slowTaskDisplayText = “Spawing actors in the level”

#global editor utility base allows you to use stuf in content browser
@unreal.uclass()
class MyEditorUtility(unreal.GlobalEditorUtilityBase):
pass

selectedAssets = MyEditorUtility().get_selected_assets()
selectedActors = MyEditorUtility().get_selection_set()
for i in selectedActors:

newSpawn = unreal.EditorLevelLibrary.spawn_actor_from_object(selectedAssets[0],unreal.Vector(0.0,0.0,0.0),unreal.Rotator(0.0,0.0, 15))
unreal.Actor.attach_to_actor(i, unreal.Name(i), unreal.AttachmentRule.SNAP_TO_TARGET, unreal.AttachmentRule.SNAP_TO_TARGET, unreal.AttachmentRule.SNAP_TO_TARGET,          False)

You are spawning a new actor “newSpawn” but you are not using it on the next line. Try…



newSpawn = unreal.EditorLevelLibrary.spawn_actor_from_object(selectedAssets[0],unreal.Vector(0.0,0.0,0.0),unreal.Rotator(0.0,0.0, 15))
newSpawn.attach_to_actor(i, unreal.Name(i), unreal.AttachmentRule.SNAP_TO_TARGET, unreal.AttachmentRule.SNAP_TO_TARGET, unreal.AttachmentRule.SNAP_TO_TARGET, False)