expressobits / inventory-system

Modular inventory system for godot 4 with nodes, compatible with multiplayer, separate logic from the UI, Using items as separate resources.
MIT License
407 stars 26 forks source link

Networked Inventory nodes make my client hang/disconnect #110

Closed warsang closed 3 months ago

warsang commented 3 months ago

Hi! So I have been playing around with an existing multiplayer project and was trying to get a networked inventory added to it. The below shows my Player scene with a NetworkedCharacterInventoryScene as a child scene. When I run without this scene, the project works fine. When I add NetworkedCharacterInventoryScene as a child scene, the game still runs but now my client hangs and eventually gets disconnected from the server when I try to connect. I tried troubleshooting myself before opening an issue but hangs are a bit harder to catch and debug over crashes.

image

I did notice that the mp player demo actually doesn't use the NetworkedCharacterInvenotry node or the NetworkedObjectPlacer node but uses it's own Synchronizer script on a simple node. What is the preferred approach (seems like the gdscript for both is very similar)

The full project is available here: https://github.com/warsang/Godot-multiplayer ( most of this stuff is from https://github.com/thegatesbrowser/godot-multiplayer and isn't mine; I've just been adding a couple of small plugins on top so far like Jolt/Phantom cam etc.)

Any help would be much appreciated.

Thanks!

warsang commented 3 months ago

Ok, I think the issue was that I didn't populate the "Inventories Path" export in my InventoryHandler. Now the client logs in and I see the open_main_inventory rpc call being fired when I press toggle_inventory but I'm not seeing the inventory displayed/show up yet.

scriptsengineer commented 3 months ago

Check that the link with the UI is working, the InventorySystemUI needs to read the character events to identify when it opened an inventory, for example.

If this is ok, check if the RPC call is arriving at the client.

If the problem persists, let me know so I can look at your code more closely.

warsang commented 3 months ago

Ok I got it to work! I was missing A LOT of stuff on my end; Thanks for the pointers; that set me into the right direction!

Documenting for whoever runs into this in the future: I didn't have the Inventroy System UI all tied up to the right NetworkedInventory nodes like you mentioned and I also had to add Nodes with the SyncInventory and SyncInventoryHandler scripts attached on my player (similar to what the example has). I also had to call inventory_system_ui.setup(inventory_system) in my _ready function from my Player script. Both values I set-up with a simple call to the following at the beginning of my Player script:

@export_node_path("NetworkedCharacterInventorySystem") var inventory_system_path = NodePath("NetworkedCharacterInventoryScene")
@onready var inventory_system : NetworkedCharacterInventorySystem = get_node(inventory_system_path)

@export_node_path("InventorySystemUI") var inventory_system_ui_path := NodePath("UI/Inventory System UI")
@onready var inventory_system_ui: Control = get_node(inventory_system_ui_path)