def test_variable(self): new_blueprint = ue.create_blueprint(Character, '/Game/Tests/Blueprints/Test2_' + self.random_string) ue.blueprint_add_member_variable(new_blueprint, 'TestValue', 'int') ue.compile_blueprint(new_blueprint) new_actor = self.world.actor_spawn(new_blueprint.GeneratedClass) new_actor.TestValue = 17 self.assertEqual(new_actor.get_property('TestValue'), 17)
def test_variable(self): new_blueprint = ue.create_blueprint( Character, '/Game/Tests/Blueprints/Test2_' + self.random_string) ue.blueprint_add_member_variable(new_blueprint, 'TestValue', 'int') ue.compile_blueprint(new_blueprint) new_actor = self.world.actor_spawn(new_blueprint.GeneratedClass) new_actor.TestValue = 17 self.assertEqual(new_actor.get_property('TestValue'), 17)
import unreal_engine as ue from unreal_engine.classes import K2Node_InputKey, K2Node_SpawnActorFromClass, Actor, Character, KismetMathLibrary from unreal_engine.structs import Key # create a new blueprint new_blueprint = ue.create_blueprint(Actor, '/Game/StrangeBlueprint') # add a member float variable ue.blueprint_add_member_variable(new_blueprint, 'Speed', 'float') # get a reference to the first graph page uber_page = new_blueprint.UberGraphPages[0] # get good coordinates for a new node x, y = uber_page.graph_get_good_place_for_new_node() # add the Speed variable to the graph uber_page.graph_add_node_variable_get('Speed', None, x, y) x, y = uber_page.graph_get_good_place_for_new_node() # add a custom event to the graph hello_world = uber_page.graph_add_node_custom_event('Hello World', x, y) # get a reference to the 'then' pin hello_world_then = hello_world.node_find_pin('then') x, y = uber_page.graph_get_good_place_for_new_node() # add a 'Spawn Actor From Class' node spawn_actor_node = uber_page.graph_add_node(K2Node_SpawnActorFromClass, x, y) # set its Class pin pin_class = spawn_actor_node.node_find_pin('Class')
import unreal_engine as ue from unreal_engine.classes import BlueprintFactory, DirectionalLightComponent, K2Node_Event import time # create new blueprint from factory bpFactory = BlueprintFactory() bp = bpFactory.factory_create_new('/Game/test' + str(int(time.time()))) # add intensity variable intensity = ue.blueprint_add_member_variable(bp, 'intensity', 'float') # set its visibility to True ue.blueprint_set_variable_visibility(bp, 'intensity', True) # add directional light component directLightComponent = ue.add_component_to_blueprint( bp, DirectionalLightComponent, "Directional_light") # add node variables (get) to the graph intensity_node = bp.UberGraphPages[0].graph_add_node_variable_get( 'intensity', None, 200, 100) directional_light_node = bp.UberGraphPages[0].graph_add_node_variable_get( 'Directional_light', None, 200, 0) # add the SetIntensity node (from DirectionalLightComponent) directional_light_set_intensity = bp.UberGraphPages[ 0].graph_add_node_call_function(DirectionalLightComponent.SetIntensity, 400, 0) # link variables intensity_node.node_find_pin('intensity').make_link_to(
def stereo_setup_level_bp_variable(player_sets=[]): from unreal_engine.classes import KismetMathLibrary, K2Node_Timeline, K2Node_ExecutionSequence, K2Node_IfThenElse world = ue.get_editor_world() level_bp = world.CurrentLevel.get_level_script_blueprint() left_channel = player_sets[0] if len(player_sets==4): right_channel = player_sets[1] else: right_channel = None pin = EdGraphPinType(PinCategory='object', PinSubCategoryObject=MediaPlayer) left_media = ue.blueprint_add_member_variable(level_bp, left_channel.get_name(), pin, None, left_channel.get_path_name()) right_media = ue.blueprint_add_member_variable(level_bp, right_channel.get_name(), pin, None, right_channel.get_path_name()) uber_page = level_bp.UberGraphPages[0] # 添加media player节点 # ---------------------------------------------- y, x = uber_page.graph_get_good_place_for_new_node() node_left_media = uber_page.graph_add_node_variable_get(left_channel.get_name(), None, x, y) y, x = uber_page.graph_get_good_place_for_new_node() node_right_media = uber_page.graph_add_node_variable_get(right_channel.get_name(), None, x, y) # 添加open source节点 # ---------------------------------------------- y, x = uber_page.graph_get_good_place_for_new_node() node_open_source_L = uber_page.graph_add_node_call_function(MediaPlayer.OpenSource, x, y) y, x = uber_page.graph_get_good_place_for_new_node() node_open_source_R = uber_page.graph_add_node_call_function(MediaPlayer.OpenSource, x, y) # 连接media source,没办法单独的设置资源,只能通过变量来设置 # ---------------------------------------------- pin = EdGraphPinType(PinCategory='object', PinSubCategoryObject=FileMediaSource) ue.blueprint_add_member_variable(level_bp, player_sets[2].get_name(), pin, None, player_sets[2].get_path_name()) pin = EdGraphPinType(PinCategory='object', PinSubCategoryObject=FileMediaSource) ue.blueprint_add_member_variable(level_bp, player_sets[3].get_name(), pin, None, player_sets[3].get_path_name()) c = uber_page.graph_add_node_variable_get(player_sets[2].get_name(), None, x, y) d = uber_page.graph_add_node_variable_get(player_sets[3].get_name(), None, x, y) pin1=c.node_find_pin(player_sets[2].get_name()) pin2=node_open_source_L.node_find_pin("MediaSource") pin1.make_link_to(pin2) pin1=d.node_find_pin(player_sets[3].get_name()) pin2=node_open_source_R.node_find_pin("MediaSource") pin1.make_link_to(pin2) # 添加>=节点, call_function的函数名可以大写也可以小写,直接按照C++文档的来就可以 # ---------------------------------------------- y, x = uber_page.graph_get_good_place_for_new_node() node_greater = uber_page.graph_add_node_call_function(KismetMathLibrary.EqualEqual_FloatFloat, x, y) # 添加branch节点 # ---------------------------------------------- i = K2Node_IfThenElse() y, x = uber_page.graph_get_good_place_for_new_node() node_branch = uber_page.graph_add_node(i, x, y) # 连接节点 # ---------------------------------------------- pin1 = node_greater.node_find_pin("ReturnValue") pin2 = node_branch.node_find_pin("Condition") pin1.make_link_to(pin2) pin1 = node_left_media.node_find_pin(left_channel.get_name()) pin2 = node_open_source_L.node_find_pin('self') pin1.make_link_to(pin2) pin1 = node_right_media.node_find_pin(right_channel.get_name()) pin2 = node_open_source_R.node_find_pin('self') pin1.make_link_to(pin2) pin1 = node_open_source_L.node_find_pin("then") pin2 = node_open_source_R.node_find_pin("execute") pin1.make_link_to(pin2) pin1 = node_branch.node_find_pin("Then") pin2 = node_open_source_L.node_find_pin("execute") pin1.make_link_to(pin2) # compile the blueprint ue.compile_blueprint(level_bp) # open related editor ue.open_editor_for_asset(level_bp) return node_branch.node_find_pin, node_greater.node_find_pin("A")
# add a cone cone = world.actor_spawn(Actor) cone.set_actor_label('A Cone') cone_mesh = cone.add_actor_component(StaticMeshComponent, 'Cone') cone_mesh.StaticMesh = ue.load_object(StaticMesh, '/Engine/BasicShapes/Cone') cone.InitialLifeSpan = 30.0 # add a better cone cone2 = world.actor_spawn(StaticMeshActor) cone2.StaticMeshComponent.StaticMesh = ue.load_object( StaticMesh, '/Engine/BasicShapes/Cone') cone2.set_actor_label('A Better Cone') # create a new bleprint bp = ue.create_blueprint(Pawn, '/Game/SuperEvilPawn') ue.add_component_to_blueprint(bp, PawnSensingComponent, 'Eyes') point_light = ue.add_component_to_blueprint(bp, PointLightComponent, 'Light') point_light.Intensity = 9999.9 ue.blueprint_add_member_variable(bp, 'SightPower', 'float') ue.blueprint_set_variable_visibility(bp, 'SightPower', False) ue.compile_blueprint(bp) # instantiate a new actor using the previously created blueprint super_evil_pawn = world.actor_spawn(bp.GeneratedClass) super_evil_pawn.set_actor_label('Super Evil Pawn') super_evil_pawn.SightPower = 2217.30 # save them all ue.editor_save_all()
import unreal_engine as ue from unreal_engine.classes import Material, BlueprintFactory, Blueprint, Actor, Texture2D, SkeletalMesh from unreal_engine.structs import EdGraphPinType, Vector, Rotator, EdGraphTerminalType from unreal_engine.enums import EPinContainerType import time bp = ue.create_blueprint(Actor, '/Game/FooActor' + str(int(time.time()))) pin = EdGraphPinType(PinCategory='object', PinSubCategoryObject=Material) ue.blueprint_add_member_variable( bp, 'TestMat', pin, None, '/Engine/MapTemplates/Materials/BasicAsset03.BasicAsset03') pin = EdGraphPinType(PinCategory='class', PinSubCategoryObject=Texture2D) ue.blueprint_add_member_variable(bp, 'TestTextureClass', pin) pin = EdGraphPinType(PinCategory='struct', PinSubCategoryObject=Vector) ue.blueprint_add_member_variable(bp, 'TestVector', pin, None, '17,22,30') pin = EdGraphPinType(PinCategory='struct', PinSubCategoryObject=Rotator, ContainerType=EPinContainerType.Array) ue.blueprint_add_member_variable( bp, 'TestRotator', pin, None, '((Pitch=0.000000,Yaw=3.000000,Roll=0.000000),(Pitch=1.000000,Yaw=0.000000,Roll=0.000000))' ) pin = EdGraphPinType(PinCategory='string', ContainerType=EPinContainerType.Map,
import unreal_engine as ue from unreal_engine.classes import K2Node_InputKey, K2Node_SpawnActorFromClass, Actor, Character, KismetMathLibrary # create a new blueprint new_blueprint = ue.create_blueprint(Actor, '/Game/StrangeBlueprint') # add a member float variable ue.blueprint_add_member_variable(new_blueprint, 'Speed', 'float') # get a reference to the first graph page uber_page = new_blueprint.UberGraphPages[0] # get good coordinates for a new node x, y = uber_page.graph_get_good_place_for_new_node() # add the Speed variable to the graph uber_page.graph_add_node_variable_get('Speed', None, x, y) x, y = uber_page.graph_get_good_place_for_new_node() # add a custom event to the graph hello_world = uber_page.graph_add_node_custom_event('Hello World', x, y) # get a reference to the 'then' pin hello_world_then = hello_world.node_find_pin('then') x, y = uber_page.graph_get_good_place_for_new_node() # add a 'Spawn Actor From Class' node spawn_actor_node = uber_page.graph_add_node(K2Node_SpawnActorFromClass, x, y) # set its Class pin pin_class = spawn_actor_node.node_find_pin('Class') pin_class.default_object = Character
import unreal_engine as ue from unreal_engine.structs import EdGraphPinType world = ue.get_editor_world() level_bp = world.CurrentLevel.get_level_script_blueprint() pin = EdGraphPinType(PinCategory='string') ue.blueprint_add_member_variable(level_bp, 'TestString', pin) ue.open_editor_for_asset(level_bp)
cone = world.actor_spawn(Actor) cone.set_actor_label('A Cone') cone_mesh = cone.add_actor_component(StaticMeshComponent, 'Cone') cone_mesh.StaticMesh = ue.load_object(StaticMesh, '/Engine/BasicShapes/Cone') cone.InitialLifeSpan = 30.0 # add a better cone cone2 = world.actor_spawn(StaticMeshActor) cone2.StaticMeshComponent.StaticMesh = ue.load_object(StaticMesh, '/Engine/BasicShapes/Cone') cone2.set_actor_label('A Better Cone') # create a new bleprint bp = ue.create_blueprint(Pawn, '/Game/SuperEvilPawn') ue.add_component_to_blueprint(bp, PawnSensingComponent, 'Eyes') point_light = ue.add_component_to_blueprint(bp, PointLightComponent, 'Light') point_light.Intensity = 9999.9 ue.blueprint_add_member_variable(bp, 'SightPower', 'float') ue.blueprint_set_variable_visibility(bp, 'SightPower', False) ue.compile_blueprint(bp) # instantiate a new actor using the previously created blueprint super_evil_pawn = world.actor_spawn(bp.GeneratedClass) super_evil_pawn.set_actor_label('Super Evil Pawn') super_evil_pawn.SightPower = 2217.30 # save them all ue.editor_save_all()
import unreal_engine as ue from unreal_engine.classes import Material, BlueprintFactory, Blueprint, Actor, Texture2D, SkeletalMesh from unreal_engine.structs import EdGraphPinType, Vector, Rotator, EdGraphTerminalType from unreal_engine.enums import EPinContainerType import time bp = ue.create_blueprint(Actor, '/Game/FooActor' + str(int(time.time()))) pin = EdGraphPinType(PinCategory='object', PinSubCategoryObject=Material) ue.blueprint_add_member_variable(bp, 'TestMat', pin, None, '/Engine/MapTemplates/Materials/BasicAsset03.BasicAsset03') pin = EdGraphPinType(PinCategory='class', PinSubCategoryObject=Texture2D) ue.blueprint_add_member_variable(bp, 'TestTextureClass', pin) pin = EdGraphPinType(PinCategory='struct',PinSubCategoryObject=Vector) ue.blueprint_add_member_variable(bp, 'TestVector', pin, None, '17,22,30') pin = EdGraphPinType(PinCategory='struct',PinSubCategoryObject=Rotator,ContainerType=EPinContainerType.Array) ue.blueprint_add_member_variable(bp, 'TestRotator', pin, None, '((Pitch=0.000000,Yaw=3.000000,Roll=0.000000),(Pitch=1.000000,Yaw=0.000000,Roll=0.000000))') pin = EdGraphPinType(PinCategory='string',ContainerType=EPinContainerType.Map,PinValueType=EdGraphTerminalType(TerminalCategory='object',TerminalSubCategoryObject=SkeletalMesh)) ue.blueprint_add_member_variable(bp, 'TestMap', pin, None, '(("firstKey", SkeletalMesh\'"/Game/Skel001"\'),("secondKey", SkeletalMesh\'"/Game/Skel002"\'))') ue.compile_blueprint(bp) ue.open_editor_for_asset(bp)