DynamicBuffer vs Multiple Entity Approach

I am trying to solve a problem where I want show or hide certain entities when the player enters a room. For example, lets say I have the following 2 rooms, and 3 entities that I wish to show or hide.

// Rooms
Entity1 = [Room]
Entity2 = [Room]

// Entities to toggle Visbility on
Entity3 = [...]
Entity4 = [...]
Entity5 = [...]

I am using the entity event pattern to detect when the player enters a room. And what I want is to show Entity3 & Entity4 (and hide Entity5) when the player enters the room Entity1, and show Entity5 (and hide Entity3 & Entity4) when the player enters room Entity2.

I am examining two different approaches for solving this problem. DynamicBuffer vs Multiple Entity Approach (data layout of these approaches shown below). And my question is, which approach would better for this kind of problem? I am trying to wrap my head around when it would be better to use one approach vs the other.

// Dynamic Buffer Approach
Entity6 = [
  OnRoomEnter { roomEntity = Entity1 },
  ToggleEntityVisibilityBuffer { buffer = [Entity3, Entity4]}
]
Entity7 = [
  OnRoomEnter { roomEntity = Entity2 },
  ToggleEntityVisibilityBuffer { buffer = [Entity5]}
]
// Multiple Entity Approach
Entity6 = [
  OnRoomEnter { roomEntity = Entity1 },
  ToggleEntityVisibility { entity = Entity3 }
]
Entity7 = [
  OnRoomEnter { roomEntity = Entity1 },
  ToggleEntityVisibility { entity = Entity4 }
]
Entity8 = [
  OnRoomEnter { roomEntity = Entity2 },
  ToggleEntityVisibility { entity = Entity5 }
]

Providing I understood your question, I would go with buffer approach, as it is easier and I think cleaner to debug.
You can view easily buffers in inspector, so you can see all in one view. No need to flip between entities.

1 Like

I would do it differently:
each item has a reference to the room where it is located
SwitchRoomSystem reacts on PlayerEntersRoom event, iterates on all items, compare item location with the active room, and changes items visibility when necessary

or

the room has a buffer of items it contains
SwitchRoomSystem reacts on PlayerEntersRoom event and does 2 things:

  • gets buffer of items in previously active toom and hides them
  • gets buffer of items in the room being activated and shows them

or

you can parent all your items to the room, and they will get be hidden with the room automatically by the render system

1 Like

Thanks guys. The approach that made the most sense for me was the DynamicBuffer approach. Mainly because an item can be visible while the player is in more then one room.