Announcement

Collapse
No announcement yet.

Help : Replicating Inventory System

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Help : Replicating Inventory System

    Hi, I'm Creating a multiplayer game and i just added an inventory system to it, everything with the inventory system is working fine but only on server side (like:toggle open inventory, pick up item, drop item, use item, ...) but for the client side it doesn't work.

    The problem in the client side that when i open the inventory is working fine but when i try to close it, it doesn't close and the inventory of the server open by it self and i can't control my client player anymore but i can control the player of the server side from the client side window and i don't know what to do to fix it.

    also another problem, when i pick up a item with the client, it works but when i use the item i don't know which client used it and also when i drop the item from the inventory, there's two problems which are :

    1- when i drop the item with client 1 for example, only the client 1 can see it and the other client can't but when i drop with the server all client can see the item dropped by the server
    2- when i drop the item i can't pick it up again with the client but with the server i can

    also i get runtime errors when i start dedicated server :

    -----

    Error Blueprint Runtime Error: Accessed None trying to read property HUDWidget from function: 'ExecuteUbergraph_MyTestController' from node: Add to Viewport in graph: EventGraph in object: MyTestController with description: Accessed None trying to read property HUDWidget
    Error Blueprint Runtime Error: Accessed None trying to read property HUDWidget from function: 'CreateInventory' from node: Add Child to Canvas in graph: CreateInventory in object: MyTestCharacter with description: Accessed None trying to read property HUDWidget
    Error Blueprint Runtime Error: Accessed None from function: 'CreateInventory' from node: Add Child to Canvas in graph: CreateInventory in object: MyTestCharacter with description: Accessed None
    Error Blueprint Runtime Error: Accessed None trying to read property CallFunc_AddChildToCanvas_ReturnValue from function: 'CreateInventory' from node: Set Auto Size in graph: CreateInventory in object: MyTestCharacter with description: Accessed None trying to read property CallFunc_AddChildToCanvas_ReturnValue
    Error Blueprint Runtime Error: Accessed None trying to read property InventoryWindow from function: 'CreateInventory' from node: Set Visibility in graph: CreateInventory in object: MyTestCharacter with description: Accessed None trying to read property InventoryWindow
    Error Blueprint Runtime Error: Accessed None trying to read property HUDWidget from function: 'ExecuteUbergraph_MyTestController' from node: Add to Viewport in graph: EventGraph in object: MyTestController with description: Accessed None trying to read property HUDWidget
    Error Blueprint Runtime Error: Accessed None trying to read property HUDWidget from function: 'CreateInventory' from node: Add Child to Canvas in graph: CreateInventory in object: MyTestCharacter with description: Accessed None trying to read property HUDWidget
    Error Blueprint Runtime Error: Accessed None from function: 'CreateInventory' from node: Add Child to Canvas in graph: CreateInventory in object: MyTestCharacter with description: Accessed None
    Error Blueprint Runtime Error: Accessed None trying to read property CallFunc_AddChildToCanvas_ReturnValue from function: 'CreateInventory' from node: Set Auto Size in graph: CreateInventory in object: MyTestCharacter with description: Accessed None trying to read property CallFunc_AddChildToCanvas_ReturnValue
    Error Blueprint Runtime Error: Accessed None trying to read property InventoryWindow from function: 'CreateInventory' from node: Set Visibility in graph: CreateInventory in object: MyTestCharacter with description: Accessed None trying to read property InventoryWindow
    Error Blueprint Runtime Error: Accessed None trying to read property HUDWidget from function: 'CreateInventory' from node: Add Child to Canvas in graph: CreateInventory in object: MyTestCharacter with description: Accessed None trying to read property HUDWidget
    Error Blueprint Runtime Error: Accessed None from function: 'CreateInventory' from node: Add Child to Canvas in graph: CreateInventory in object: MyTestCharacter with description: Accessed None
    Error Blueprint Runtime Error: Accessed None trying to read property CallFunc_AddChildToCanvas_ReturnValue from function: 'CreateInventory' from node: Set Auto Size in graph: CreateInventory in object: MyTestCharacter with description: Accessed None trying to read property CallFunc_AddChildToCanvas_ReturnValue
    Error Blueprint Runtime Error: Accessed None trying to read property InventoryWindow from function: 'CreateInventory' from node: Set Visibility in graph: CreateInventory in object: MyTestCharacter with description: Accessed None trying to read property InventoryWindow
    Error Blueprint Runtime Error: Accessed None trying to read property HUDWidget from function: 'CreateInventory' from node: Add Child to Canvas in graph: CreateInventory in object: MyTestCharacter with description: Accessed None trying to read property HUDWidget
    Error Blueprint Runtime Error: Accessed None from function: 'CreateInventory' from node: Add Child to Canvas in graph: CreateInventory in object: MyTestCharacter with description: Accessed None
    Error Blueprint Runtime Error: Accessed None trying to read property CallFunc_AddChildToCanvas_ReturnValue from function: 'CreateInventory' from node: Set Auto Size in graph: CreateInventory in object: MyTestCharacter with description: Accessed None trying to read property CallFunc_AddChildToCanvas_ReturnValue
    Error Blueprint Runtime Error: Accessed None trying to read property InventoryWindow from function: 'CreateInventory' from node: Set Visibility in graph: CreateInventory in object: MyTestCharacter with description: Accessed None trying to read property InventoryWindow


    -----

    if anyone knows how to fix these problems please help me and all the information my different blueprints are linked and thanks
    Last edited by RevengeViRusS; 08-15-2018, 08:06 AM.

    #2
    Anything related to your widget blueprints shouldn't be using any form of RPC's.

    Widgets only exist on clients so instructing the server to open one is pointless (keep in mind this is in the case of a dedicated server, the listen server can have its own widgets because it's also a client, but try focus on the dedicated server case for clarity of mind).

    Variables that are set on the server can be accessed by widgets when they are replicated, or alternatively if they are explicitly set by using the an event set to "Run On Owning Client" inside a class that can communicate with the server.

    You can change variables on the server from widgets using "Run On Server", just keep in mind that you must call the "Run On Server" RPC from a class that can perform RPC's (PlayerController, PlayerState, PlayerCharacter, or components therein).

    i.e. when running an OnButtonPressed event in a widget blueprint you'll want to get reference to your controller ("Get owning player" > Cast to "MyPlayerController") and call an event on your controller blueprint. After that call an event that is set to "Run On Server".

    Everything after the "Run On Server" will then be running on the server.

    For example, if you're trying to use an item, let's say a Water Bottle, and you have a button on your inventory widget that says "Use Item". On pressing the Use Item button, the widget blueprint will then run "OnUseButtonPressed" (or whatever you call it). From here you want the server to run the Drink Water logic, to get to the server you can arrange the a remote procedure call in the following way:

    WidgetBlueprint:

    On Button Pressed > Cast To "MyPlayerController" > Call "UseItem" Event

    MyPlayerController Blueprint:

    Runs Event "UseItem" - You now need to get this to the server, create a new Event (e.g. SERVER_UseItem) and set it to Run On Server ( make it reliable for something like using an inventory item).

    Call "SERVER_UseItem" after the "UseItem" Event.

    Runs Event "SERVER_UseItem" - Everything after this point will be running on the server, this is generally where you want to do anything and everything gameplay related.
    _________________________________________________________________________________________________________________________________________________________


    When you are getting an error that says "Accessed None" that is exactly what it means. The server is trying to get nothing. Also your use of the Switch Has Authority looks to be incorrect. Unfortunately the only cure for this is intense study of the documentation and examples, it takes a long time for things to start making sense, and just when it does start making sense it'll become way more confusing.

    Replication is an extremely complicated topic. I suggest close study of the documentation (over and over and over),

    https://docs.unrealengine.com/en-us/Gameplay/Networking

    Perhaps download the ARPG Inventory project from the marketplace and study how it handles passing functions to the server.

    Sorry I couldn't provide blueprint examples as i'm not currently near my computer with the engine on it, will try and do later. Hopefully this helps.

    Comment


      #3
      Oh sorry I just noticed the example you provided. Ok so....

      1- when i drop the item with client 1 for example, only the client 1 can see it and the other client can't but when i drop with the server all client can see the item dropped by the server

      I assume here when you drop the item you're calling "Spawn Actor From Class", it makes sense that the other client can't see it because you're calling it on the client so therefore it only exists on the client. You need to spawn the item on the server, you can do so by following the same process in the above Drink Water example. When on the server, spawn the item and manipulate your inventory from here.

      In the case that you're just teleporting and unhiding the item then all this also needs to occur on the server.

      2- when i drop the item i can't pick it up again with the client but with the server i can.

      Sounds like something that's occuring when you're using the listen server client.

      Don't forget to check bReplicates is set to true in your actor class (the item or whatever).
      Last edited by GrumpyNZ; 08-18-2018, 07:53 AM. Reason: After looking at some of the pics, Spawn Actor From Class being used in a Widget Blueprint is a no-no if you want that spawned actor to replicate to other clients.

      Comment

      Working...
      X