Hi
I’m having some issues with this module. My usecase is to send positions of NPCs from the server to clients as efficiently as possible.
I’m using the following packet structure (ByteNetPackets module):
local ByteNet = require(game:GetService("ReplicatedStorage"):WaitForChild("ByteNet"))
return {
NPC_ControllerPos = ByteNet.definePacket({
-- This structure field is very important!
structure = {
id = ByteNet.uint16, -- values from 0 to 65536-1 (more than enough for NPCs)
pos = ByteNet.vec3,
},
--reliabilityType = "unreliable",
})
}
The ID field is required to identify which NPC the movement is for.
I’m sending the position every 0.1s for each NPC on the server:
-- Send updated position to all clients that we're replicating to (this is only called if we're actually moving)
-- Don't send orientation to save network replication bandwidth
for _, v in pairs(self._playersReplicatedTo) do
ByteNetPackets.NPC_ControllerPos:sendTo({ id = self._id, pos = self._currentCFrame.Position }, v)
--movementRemote:FireClient(v, tostring(self._id), self._currentCFrame.Position)
end
Unfortunately I’m noticing that the client network recv is pretty much the same (even slightly higher!) compared to the unreliable remote event I was using before. That was simply sending the id as a string, and position as a Vector3, as you can see commented out.
Also I can’t use ‘unreliable’ mode without packets being dropped (size limit of 900KB). ‘movementRemote’ is unreliable and that worked perfectly before, so I’m not sure why it doesn’t work anymore. Perhaps the module internally puts packets together in one bigger packet?
What can I do to optimize the send, and be able to use unreliable remotes?
One thing I tried, was sending the x, y and z components as float32s, but your module already does that behind the scenes so that didn’t improve much.
Thanks
P.S.
Minor QoL issue, but the ByteNetPackets.NPC_ControllerPos:sendTo({ id = self._id, pos = self._currentCFrame.Position }, v)
line is being linted as an error in Roblox Studio. No error related to it in-game though.