import time


def wait_for_ego_vehicle(world):
    """Loops until a hero vehicle is spawned.

    Note: The loop ticks the simulation.
    """
    # Connect to the ego-vehicle spawned by the scenario runner.
    while True:
        time.sleep(1)
        possible_actors = world.get_actors().filter('vehicle.*')
        for actor in possible_actors:
            if actor.attributes['role_name'] == 'hero':
                return actor
        world.tick()