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

change_property of object cannot change img_name #325

Closed
NikkiBouman opened this issue Apr 21, 2022 · 2 comments
Closed

change_property of object cannot change img_name #325

NikkiBouman opened this issue Apr 21, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@NikkiBouman
Copy link

Describe the bug
I am trying to change the image of the object that is being carried as soon as it gets dropped (for example: square when picking up, circle when being put on the ground). I can change every property (for example "is_movable" can be set to False), except for the "img_name".

To Reproduce
I have my own custom action from the carrying objects together case.

class LowerObject(DropObject):
    def __init__(self, duration_in_ticks=0):
        super().__init__(duration_in_ticks)

    def mutate(self, grid_world, agent_id, world_state, **kwargs):
        # get robot and human ids
        global robot_id
        global human_id
        # get the robot and human
        robot = grid_world.registered_agents[robot_id]
        human = grid_world.registered_agents[human_id]
        # check who is carrying to get the object
        if human.is_carrying:
            obj = human.is_carrying[0]
        else:
            obj = robot.is_carrying[0]
        obj_id = obj.properties['obj_id']
        # change object properties
        obj.change_property("name", "broken")
        obj.change_property("img_name", "broken_light_box_human.png")
        obj.change_property("is_movable", False)
        kwargs["object_id"] = obj_id
        return super().mutate(grid_world, agent_id, world_state, **kwargs)

Expected behavior
At properties, the "img_name" should change to "broken_light_box_human.png". However, it does not change.

@NikkiBouman NikkiBouman added the bug Something isn't working label Apr 21, 2022
@NikkiBouman
Copy link
Author

I fixed it by adding the following three lines:

            elif property_name == "img_name":
                assert isinstance(property_value, str)
                self.custom_properties["img_name"] = property_value

Into the change_property function of env_object.py. Probably not how it's supposed to be fixed, but it works

@thaije
Copy link
Collaborator

thaije commented May 27, 2022

Hi Nikki,

I tried to reproduce this issue in various conditions and this is what I figured out:

Changing an image of an agent that already had an image (img_name set when you added your agent in your scenario file with factory.add_human_agent..) works in the manner that you described. However, there are some reasons why it could fail:

  • The object/agent didn't have an img_name set on creation, and as such doesn't have the img_name property. In that case, use the add_property() function instead.
  • The path to the image is not correct.

I will add an exception in the case that change_property() is called for a property that doesn't exist (yet).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants