static property contentIds on Inventory component is a reference across entities
See original GitHub issueThis is another weird one but I don’t see anywhere in my codebase where I am explicitly assigning the property in a way that would create a reference so I figured I’d submit a bug report. For context, I based the Inventory, Loot, and take/drop eventing on your game sleepy.
Actual Behavior
I have two actors in my game, the player and a goblin. They both start with an empty Inventory. If either actor adds an item to their Inventory, it will appear in the contentIds array for both actors.
Expected Behavior
Inventory contentIds should not be shared across entities.
Repro
Clone and install this branch.
Open the console in dev tools. Using your mouse, click on the @
and g
to log all entities at both locations to the console. Inspect the @
and g
entities to confirm that they both have an Inventory component and that inventory.contentIds array is empty.
Use the arrow keys to navigate to a lockpick ~
press the i
key when adjacent to the lockpick to activate the interactions menu. Use the a
key to pick up the lockpick.
Using your mouse, click on the @
and g
to again log all entities at both locations to the console. Inspect the @
and g
to confirm that they both have an Inventory component and that inventory.contentIds contains the same id.
Furthermore you can test that they are a reference with the following script in the console (wrld is a global reference to the current world object)
wrld.getEntity(<playerEntityId>).inventory.contentIds == wrld.getEntity(<goblinEntityId>).inventory.contentIds
// returns true
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:5 (4 by maintainers)
Top GitHub Comments
@luetkemj this should be fixed in
geotic@4.3.0
Followup
If I assign contentIds to an array in the onAttatched hook - they do not share a reference.
I’m wondering if this might be an issue with array type properties in general - I don’t think I really have any others in my game yet that would have been tested in the way.