Managing child node responsibilities?

Say I have a Game node which contains a Player scene which contains a Inventory node. For coordination the Game might respond to an event and want to get the most recently added Inventory item.

  1. To facilitate loose coupling and extensibility, would you call a method on the Player’s Inventory node directly from the Game node? This seems brittle and tightly coupled as the inventory is the player’s concern?
  2. Alternatively the Player could have some ‘handover’ method calls to call Inventory methods only for the purpose of exposing it, but this seems very verbose and cluttering up the methods in the Player’s script?
  3. Extending a CorePlayer script that handles this is also an option for organisation purposes, but of course the Player might have other components that need managed, besides Inventory, so that’s just moving the problem?

I’m not really sure how to deal with this part of game architecture, what works for you?

There are lots of considerations here, but making some assumptions:

  • your inventory is more complex than “2 keys + 500 gold”, you have item use, things that can be equipped &c. that require a management screen
  • there’s one player whose inventory needs managing, if other things have inventory it’s simplified, like “this kobold has 4 darts and a healing herb”
  • inventory is part of the save state for the game

I’d personally be inclined to cut the problem into an inventory data store and a separate inventory user interface. I’d probably put the data store in a global script called Inventory, so from anywhere you can do:

Inventory.add_item(thing)

if Inventory.use_health_potion():
    PlaySound.health_up()
else:
    PlaySound.not_in_inventory()

Splitting the UI from the data management makes changes and maintenance easier for both. You’ll probably want to tweak the inventory UI a lot over the course of development.

Thanks but, my question is specifically around when one or more parents of a scene needing to interact with a child in a scene. The Player Inventory example is just illustrative btw.