Need help with an issue with replicating a component

Hi all,

I’m running into a weird issue that’s driving me crazy. I have an inventory component on my character. That component object holds a few arrays for different inventories (primary/secondary weapons, ammo, throwable items, healing items, wearable items) which are all replicated. I’m having an issue where, for some reason, when replication is enabled on the component, clients that connect can’t move when they spawn, and they can’t see the host moving around (although the host can move around just fine). Certain things do replicate like when I hit K to suicide; a death animation plays and a new pawn is spawned for the player, but again, they can’t move it.

I need this component replicating because I only want the server making updates to inventories for obvious reasons. Does anyone know why this is happening? Do I have too many things replicated in the component? I wouldn’t think so, it’s really just a few arrays and they’re empty until I start grabbing items.

I take it the server is spawning the physical items (weapons/wearables) and attaching them to the pawn. Are you setting ownership of said items to the pawn?

Anything spawned by the server is owned by the server, thus the server is the only entity that can move them. The host player can move because its also the server.

When players first get in, they have nothing in their inventory, it’s a Battle Royale-esque state right now. I am understanding the server-client model but I’m really at a loss as to what’s wrong here. Disabling replication on the inventory component lets the clients move just fine, but I need the replication on.

That’s an odd one for sure. How are you replicating?

What I see is happening is that even though I am setting a “CharacterPawn” variable in my controller in the On Possess event, that variable is coming up empty when being validated when input keys are pressed. I’ve tried several ways to force it to get set right. It blows my mind because if I set a breakpoint on the “Set CharacterPawn” node, I see the pawn being assigned there fine. How the heck is it empty right after… this is probably the answer I need. The server (game mode) is spawning the character and possessing it with the player’s controller, but for some reason the client’s controller isn’t keeping the pawn variable when it gets set.

I am just using the UE replication option, not sure what you mean by “how” am I replicating.

You might have to set up a timer event that sets the reference. Loop until its valid.

Init Pawn (custom event) :: Get controlled pawn -> cast -> set reference -> is valid -> false -> set timer by function (Init Pawn)

Holy **** it’s ridiculous this is necessary. I think it’s working! Let me test a few things. Thanks much for your help!

False alarm, I had the component not set to replicate :frowning: Still seeing the same issue.

One thing I’m not understanding, it looks like I had to make my CharacterPawn variable replicated for it to work. Doesn’t each client own their controller? The “On Possess” event is triggered on the client as far as I’m seeing, so I’m boggled as to why the pawn variable had to be set to replicated.

The one tricky thing I have to figure out here is, I have two different characters (for non-VR and VR). Since I’m using the failed node from the cast for the non-VR character for the timer function, I have to figure out how to throw the cast to the VR character somewhere in there.

OMG man. You’re probably going to crack up at this.

The real issue, all along, is that in my “Prepare Inventory” function (which sets the array lengths up for the different inventories I have) was setting one of the arrays to 255. I’m assuming UE did NOT like that. I set it to 6 (I’ll play with the number more) and I think things are finally shaping up. I find it weird UE would have trouble with that. The array is empty, it just has 255 empty rows.

Lol, it happens. :slight_smile: