Breakthrough


Hi everyone,

I'm a few days late because I wanted to finish the changes to the items and stuff finished. I had a big mental breakthrough! After I got the items refactored I worked on getting item pickup and drop off working on both server and client. I was struggling a bit to wrap my head around UE4's networking and replication. I finally grasped it though, and got the features working. I think it'll be a lot easier from here on out working on networking features. 

Last update I said I would go into more detail about the refactor I did. I don't have images to compare, but I'll upload the changes to my public repo. So, initially the items worked like this. First the player would walk over an actor. OnOverlapBegin would check a public actor tag on it to see if it was a stealable item. If so a pointer to that item is stored in a list of items near the player. When the player hits the pickup button it grabs the last pointer on that list grabbed and sent to the item holder on the player controller to be stored. Only the gameplay tag of the item, which identified what type of item it was, was stored. Lastly the item was destroyed. When dropped off the tag would be taken from the player's holder, be compared to a list of enums stored on the drop off actor. This comparison would let the actor figure out what points to award the player. I initially thought that this method would save on memory, since the only thing being exchanged and stored was a gameplay tag. I turned out to be really obtuse.

Alright so what did I do? I got rid of the tags, and created a data table for the items. This way items can be easily added, modified, and identified. Now a struct stores the info for each item. When the player walks over an actor it casts that actor to an interactable object actor. If the cast comes up null the process ends. Otherwise it then identify if that actor is an item or security point based on an enum stored on the class. It'll still store the item in a list like before, but the list is of that interactable actor class. The item is picked up like before, but when the player controller calls a server rpc to get the server version of the player controller, and item holder. The item holder will store the attached item info struct and destroy the original item on the server. The destruction, and storage replicate down to the appropriate client(s). The drop off point gets that struct from the server item holder, and immediately has all the info of the item it needs. This is far easier to implement, validate, and change/update in the future. Now the drop off class doesn't need to compare tags to enum, and gather info from there. It just reads the struct, and the structs data is populated through an updatable data table.

I hope this made any sense, and If you come across this with some ideas for improvment leave a comment. Otherwise it's kind of late, so I'll be off.

Thanks,

Jon

Leave a comment

Log in with itch.io to leave a comment.