Download

Action RPG Inventory System

Yeah it has been brought up before its a lot easier just adding slots to the inventory as the logic’s there already which is what im doing.

Has anyone else tried to set this up when using a dedicated server?

My current problem is when I press E to pick up an item, the item does not get picked up. And it seems I’m getting a None error for Player Inventory when the player connects and I initialize the character. I believe the E problem is stemming from the None error.

This used to work when in PIE using the Run Dedicated Server and Auto Connect to Server flags, but now that I’m running my own processes and only connect via Join Session, it does not work.

Any ideas?

4971856e2aa0ef3a6e5bde9d4a986a8423922666.png

The ‘None’ means that the PlayerInventory reference used by the InventoryManagerComponent is NULL and not set.
This reference should be set when your Player Controller initializes the Inventory System to your Player’s InventoryComponent (EquipmentInventoryComponent)
You can see how this is setup in the original Demo content in this screenshot.

Also in 4.11+ please make sure in your Project Settings you have the correct Global Default Server Game Mode setup.
You can see where to set the Server Default Map and Game Mode in this screenshot.

If all that is fine, I think what could also be causing the issue is Event BeginPlay. Event BeginPlay is not very multiplayer friendly and in the InventorySystem I added a delay to give the server time to replicate to the client before initializing components. This was a simple fix to avoid over complicating things by adding in a Game State Management Framework which is way out of scope for an Inventory System.

For now increase the delay to give the server more time to load in the client before trying to initialize components during Event BeginPlay.
Create a proper loading/management system for your clients using the Game Mode class and overriding events like OnPostLogin, OnRestart Player, etc… (In the Western Multiplayer Shootout example Epic provides an example of setting this up) and replace using Event BeginPlay with your own Custom Event for initializing YourPlayerController.

Yes, I override OnPostLogin, and I have the server do something similar to what Multiplayer Shootout does in that it gets the Player Start, spawns my Character there, and has the Player Controller Possess that new Character. Right after Possess, I call an init function on the owning client with the player controller as the target, which in turns starts the setup of the Inventory in the Player Controller.

The HUD shows up correctly, but the error occurs with the PlayerInventory and I can’t pick up items.

As a note, I’m still in 4.10.

Nevermind about the delay in the OnPostLogin, it didn’t work.

If you have a proper setup in your project then you shouldn’t need a delay.

It’s hard to say for sure what is causing the issue in your project, but the inventory system works just fine on dedicated server.
Best to try and see what is causing the PlayerInventory Null Reference in your initialize because if the player doesn’t have an inventory it can’t pickup items :slight_smile:
try putting some print strings to see if your init function is finishing properly.

If you have a proper setup in your project then you shouldn’t need a delay.

Best to try and see what is causing the PlayerInventory Null Reference in your initialize, because if the player doesn’t have an inventory it can’t pickup items :slight_smile:
Try putting some print strings to see if your init function is finishing properly.

OK, I think I found the problem.

For starters, I checked both the Inventory Manager Component and the Player Inventory Component on my Player Controller and they both were not NULL.

Next, I decided to replicate the Player Inventory variable and initialize it with a server RPC instead of what you showed in your screenshot above.

This removed the Accessed None errors on the server.

However, I still can’t pick up anything.

I think this is because the server doesn’t know where to look when doing the line trace. I was dealing with server/client line traces in another thread. Essentially, here, when you press E, you call the Server_OnActorUsed function, which is a server RPC which will then call OnActorUsed. OnActorUsed will then call GetUsableActor, which is where the line trace happens. So in the Get Usable Actor function it uses the Character Reference and uses that reference’s Follow Camera and Camera Boom to create the two vectors needed for the line trace. However, Follow Camera and Camera Boom aren’t replicated, so the server will have no idea where to start and end the line trace. In fact, I put a Print String right after the Is Valid check on the character reference on the Is Not Valid side and it printed a string on the server, meaning the character reference is NULL.

So I think to fix this, I’m going to have to make sure that Character Reference and Equipment Character Reference are both replicated and initialized with RPCs similar to PlayerInventory. And then I’m going to need to fix the Server Line Trace to use the proper location and rotation of the cameras, which will require either setting up replicated camera variables or just passing in the start and end trace vectors through the RPC.

Awesome to see your progress OverRated_AU ! It’s cool to see all that’s possible with this system.

You were right Pirate about using the UpdateStats function to add events on item equip, that worked wonders.

I started working a bit on lootable enemy characters, and for some reason I realized I can’t loot either Tandy or Muppet anymore. I seem to be able to loot everything else ( items, skeletons and pots), just not characters for some reason. Any idea where that might come from ?

Edit : (I’m getting an error from the ‘characterreference’ node in the getusableactor, which probably is the source of the error ? )

In the Action RPG Inventory System demo player controller this is already setup to address those issues. I am not sure what is different in your project without being able to see it myself.
You said everything works fine when you play in editor with dedicated server checked, so I’m not sure why you would need to make any code changes in your project to get things to work with your projects dedicated server.

You shouldn’t need to set the PlayerInventory to replicate because of how Unreal works. The client and the server will both run the initialization code.
But since you have your own setup for initializing your player controller you need to make sure the server version is setting the PlayerInventory when it inits the InventoryManagerComponent.

If you look at the Demo init function you can see what gets called by the server/client and what gets called by the client only in this screenshot.

But none of this explains why it works normally, but not with your projects dedicated server.

Is this migrated into your own project? Muppet and Tandy are setup with the Interface to make them lootable and have the EquipmentInventoryComponent like a player has. Maybe during your migration the interface was unhooked?
It’s very similar setting up a character to be looted as any other actor like the loot containers. They just need an InventoryComponent and the Usable Actor Interface and Inventory Interface and the implementation of the interface functions.

Yes that is migrated into my own project :slight_smile: Oh you’re right I was just forgetting to actually add the ‘inside’ of the functions, they were there but just had the base and return node for some. That’s super helpful for the lootable players.

However I’m still having an issue with those NPCS…If I switch back to both inventoryplayer and the controller instead of mine, the NPCS work, but not with my character. My character can still open pots/ skeletons and pick up items though.

In your Demo controller, you initialize via BeginPlay, which is called by both Server and Client.

I guess I can call the Initialize twice when the Client joins the server, once by Server and once by Client.

Yes, this worked. Just for a future reference for anyone who does implement the Gameplay Framework (using GameMode to control client spawning) and wants to make sure everything spawns correctly when loaded instead of using the BeginPlay with delay, the initialization needs to be called by both the server and the owning client right after Character possess in the OnPostLogin.

I am glad you got it worked out :smiley:

You need to update the OnActorUsed() functions inside Muppet and NPC (Since the Tandy example is a child of NPC) and change the Cast node Cast To Inventory Player Controller to cast to your own player controller.
That’s why it works normally but not with your player controller.

Do you mean the Controller possess?

I
Yup again that worked. And thanks to your explanations, I have a much better understanding of the system as a whole now :slight_smile: Is there anything I need to do to have my starting loadout be in the actual equipement sheet also ? Right now if I try to loot someone else, I can loot them all good, and I do have my starting items as well on me, but I can’t see them in the equipment slots if that makes sense. Like my helmet is visible on me, but I cannot see any of those items equipped when on the character equipement sheet ( when I press C basically there’s nothing there) .

I need some help with the Action RPG Inventory System. I have about 99% successful integration of your plugin into our game project, but I’m stuck on one bug that I cannot seem to track down. When an item is looted from Muppet (or other), the associated mesh item is removed from Muppet’s body, added to the player’s inventory, but the item image/slot is not removed from the container window. The icon will not go away but when all items are looted, the window closes like it’s supposed to and cannot be opened again. Could you please assist?

I would like to request some help with the Action RPG Inventory System. I have about 99% successful integration of your plugin into our game project, but I’m stuck on one bug that I cannot seem to track down. When an item is looted from Muppet (or other), the associated mesh item is removed from Muppet’s body, added to the player’s inventory, but the item image/slot is not removed from the container window. The icon will not go away but when all items are looted, the window closes like it’s supposed to and cannot be opened again. Could you please assist me with this issue?

Yeah, the target Controller possesses the passed in Pawn in the custom GameMode event called during the OnPostLogin event which is also in the GameMode.

possessinit.PNG

The first Custom Character Init is an event, (which is being called on the server since we are in my custom GameMode) in my custom Character blueprint that sets up certain variables and will eventually call the initialize event in my custom Player Controller that will set up the Inventory. The second is a RPC to the owning client which will eventually call the same init function on my Character blueprint. So first server, then client calling the same intialize.

What version are you using? and if it’s an older version have you applied all the updates? The Inventory UI refreshes to reflect your startup items already in the project. Perhaps something got unhooked when you migrated? Or you are initializing the Client Inventory UI before loading your Startup Items on the Server.

In your Initialization the Server Inits the Inventory/Loads the startup items into the Players Inventory(Remember all items are owned by the Server on the Server version of the InventoryComponent, the Client just gets it’s UI updated to show what they have) then after that you would call on the Client *InventoryManagerComponent->*Client Load Inventory as this is where the UI gets initialized/built for the Client. If there are items in the Server Inventory when you initialize the Client UI it will call the Event Server Refresh Inventory Slots after it’s finished creating the Client UI. This event will make sure that all items on the Server will sync to the Client UI.

reload_inventory_UI.png

If you need to refresh the whole UI on the Client yourself you can always call the Event Server Refresh Inventory Slots as a simple way to sync the Client UI with the Server Inventory Items.
But since your issues is with startup items simply initializing the Client UI after loading the startup items will do it for you.