Exemple #1
0
def step(message):
    """
    Performs a single step in the game (could be several ticks) given some action/axis mappings.
    The number of ticks to perform can be specified through `num_ticks` (default=4).
    The fake amount of time (dt) that each tick will use can be specified through `delta_time` (default=1/60s).
    """
    playing_world = util.get_playing_world()
    if not playing_world:
        return {"status": "error", "message": "No playing world!"}

    delta_time = message.get(
        "delta_time",
        1.0 / 60.0)  # the force-set delta time (dt) for each tick
    num_ticks = message.get(
        "num_ticks", 4
    )  # the number of ticks to work through (all with the given action/axis mappings valid)
    controller = playing_world.get_player_controller()

    ue.log("step command: delta_time={} num_ticks={}".format(
        delta_time, num_ticks))

    # DEBUG
    #pydevd.settrace("localhost", port=20023, stdoutToServer=True, stderrToServer=True)  # DEBUG
    # END: DEBUG

    if "axes" in message:
        for axis in message["axes"]:
            # ue.log("-> axis {}={} (key={})".format(key_name, axis[1], Key(KeyName=key_name)))
            controller.input_axis(Key(KeyName=axis[0]), axis[1], delta_time)
    if "actions" in message:
        for action in message["actions"]:
            # ue.log("-> action {}={}".format(action_name, action[1]))
            controller.input_key(
                Key(KeyName=action[0]), EInputEvent.IE_Pressed
                if action[1] else EInputEvent.IE_Released)

    # unpause the game and then perform n ticks with the given inputs (actions and axes)
    for _ in range(num_ticks):
        was_unpaused = GameplayStatics.SetGamePaused(playing_world, False)
        if not was_unpaused:
            ue.log(
                "WARNING: un-pausing game for next step was not successful!")

        # TODO: how do we collect rewards over the single ticks if we don't query the observers after each (have to always accumulate and compare to previous value)?
        playing_world.world_tick(delta_time, True)

        # after the first tick, reset all action mappings to False again (otherwise sending True in two succinct steps would not(!) repeat the action)
        if "actions" in message:
            for action in message["actions"]:
                controller.input_key(Key(KeyName=action[0]),
                                     EInputEvent.IE_Released)

        # pause again
        was_paused = GameplayStatics.SetGamePaused(playing_world, True)
        if not was_paused:
            ue.log("->WARNING: re-pausing game after step was not successful!")

    return util.compile_obs_dict()
Exemple #2
0
def fn_SaveDefaultSetting():
    try:
        openpath = ue.open_directory_dialog('')
        dt_factory = DataTableFactory()
        dt_factory.Struct = Key
        key = Key()
        key.KeyName = openpath
        dt = dt_factory.factory_create_new(
            '/Game/Assets/ZExperiment/Scripts/IM_ResourceCheck/DefaultSetting')
        dt.data_table_add_row("{0}".format('TablePath_' + str(0)), key)
        dt.save_package()
        return openpath
    except:
        return ''
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

# get a reference to its 'exec' pin
spawn_actor_node_exec = spawn_actor_node.node_find_pin('execute')

# link the hello world event to the spawn actor node
hello_world_then.make_link_to(spawn_actor_node_exec)

x, y = uber_page.graph_get_good_place_for_new_node()
# create a 'make transform' node
make_transform = uber_page.graph_add_node_call_function(
    KismetMathLibrary.MakeTransform, x, y)

# link the return value of 'make transform' to the 'SpawnTransform' pin of the spawn actor node
make_transform.node_find_pin('ReturnValue').make_link_to(
    spawn_actor_node.node_find_pin('SpawnTransform'))

input_key = K2Node_InputKey(Outer=uber_page)
input_key.InputKey = Key(KeyName='SpaceBar')
input_key_node = uber_page.graph_add_node(input_key, 400, 400)

# compile the blueprint
ue.compile_blueprint(new_blueprint)

# save it
ue.editor_save_all()
 def test_cmp(self):
     key1 = Key(KeyName='SpaceBar')
     key2 = Key(KeyName='SpaceBar')
     self.assertEqual(key1, key2)