Hey! I’m pretty new here. I’m making a project in blueprints in a hybrid project in UE 5.4. The project uses replication and the bug seems to be in the replication.
Due to “new user” restrictions, please see the following imgur album for blueprint screenshots
I’m making items that a character can pickup and drop. There are two master blueprints for items:
- BP_ItemMaster, from which in-hand items are parented. It contains the logic for using the item, as well as a reference to the BP_PickupMaster of the item.
- BP_PickupMaster, from which on the ground items are parented. It contains the logic for picking up the item, and has a reference to the BP_ItemMaster of the item.
The bug is that, when in a session, if a player picks up an even number of times an item (2, 4, 6, …), another player reconnecting to the session will not see the item and will not have a reference to the item in the character (when it should). This does not happen on uneven numbers of times a player picks up an item (in this case, the reconnecting player sees the item and has references correctly).
I can’t find why it is this way, so I’m hoping someone can spot my error in my blueprints. I’ll try to explain as best as I can:
When picking up an item, the player (server side) makes a line trace to the direction it is facing. If it collides with a BP_PickupMaster, that pick up object will send an event Interact via an interface to the player picking up. The inputs are pickup for the pickup object and item class for the BP_ItemMaster class referenced in the BP_PickupMaster. A validated get node for equipped item is used to make sure the player does not have an item equipped while picking up another item. For simplicity, let’s assume both casting fail. A variable called Equipped Item Class will be set with the item class input and is replicated. A swap boolean RepNotified will then trigger the picking up logic for everyone. The kill node at the end simply destroys the BP_PickupMaster object.
Please see imgur album Image 1
We then go to the Swap Repnotified event, where we print the item class (when the bug occurs, this print is blank). We then add the item to the character by its class and set it as the equipped item variable (not replicated). Let’s still assume both cast fail, and we trigger an Attach Item event on the item directly. We then check for authority and set an Anim Index RepNotified, which handles animation. The last part of the blueprint is not relevant here.
Please see imgur album Image 2
Attach Item, directly on the item, checks for pawn ownership and attach the item either to the first person mesh or the third person mesh.
Please see imgur album Image 3
Here’s also the Anim Index Notified event just in case. It should not be relevant to my problem.
Please see imgur album Image 4
The item is successfully equipped! Now to drop it.
Pressing the drop item input will trigger the following event called ROS_Drop. It is run on server. The event first checks if the player has an item equipped with a validated get, then draws a linetrace from the character to find either the end of the line trace or the point of contact with something. It then gets the BP_PickupMaster reference from the equipped item and spawns a new actor from that reference at the point of impact/end point of the line trace. Again, both cast will be assumed to fail. We set the Anim Index RepNotified again, then we swap a reset equipped item boolean RepNotified.
Please see imgur album Image 5
The Reset Equipped Item RepNotified handles getting rid of the item. It first has a validated get for the equipped item to make sure what we want to destroy exists. Then, it prints a debug log before destroying the equipped item component. It then uses an equipped item REF variable (which is a variable of null value but of same type as equipped item) to reset the equipped item variable. The event then proceeds to remove any input context that might have been added for use with the item.
Please see imgur album Image 6
And that’s everything! So for some reason it works if you pick up one, three or five items, but not if you pick up two or four of them. The failing point seems to be the Item Class in the Swap RepNotified event, since the debug prints nothing when the bug happens when the client reconnects, and when there is no bug it prints the name of the item class correctly. Before reconnecting, every log shows correct functioning of the whole thing.
I know it’s a lot to ask but I’ve been looking at it for two hours and I have no clue what’s going wrong. Feel free to ask anything if you need more info to help me, I’d be glad to provide it to you!