Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add prefix to object before spawning to avoid object registered twice in engine #659

Merged
merged 3 commits into from
Mar 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions metadrive/manager/scenario_light_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
class ScenarioLightManager(BaseManager):
CLEAR_LIGHTS = False

OBJECT_PREFIX = "traffic_light_"

def __init__(self):
super(ScenarioLightManager, self).__init__()
self._scenario_id_to_obj_id = {}
Expand Down Expand Up @@ -41,12 +43,15 @@ def after_reset(self):
)
lane_info = self.engine.current_map.road_network.graph[str(scenario_lane_id)]
position = self._get_light_position(light_info)
name = scenario_lane_id if self.engine.global_config["force_reuse_object_name"] else None
name = self.OBJECT_PREFIX + scenario_lane_id if self.engine.global_config["force_reuse_object_name"
] else None
traffic_light = self.spawn_object(ScenarioTrafficLight, lane=lane_info.lane, position=position, name=name)
self._scenario_id_to_obj_id[scenario_lane_id] = traffic_light.id
self._obj_id_to_scenario_id[traffic_light.id] = scenario_lane_id
if self.engine.global_config["force_reuse_object_name"]:
assert scenario_lane_id == traffic_light.id, "Original id should be assigned to traffic lights"
assert self.OBJECT_PREFIX + scenario_lane_id == traffic_light.id, (
"Original id should be assigned to traffic lights"
)
self._lane_index_to_obj[lane_info.lane.index] = traffic_light
status = light_info[SD.TRAFFIC_LIGHT_STATUS][self.episode_step]
traffic_light.set_status(status)
Expand Down
Loading