I am working on a RTS and I decided to move my unit controllers ( what makes them shoot ) to the client to reduce lag. When a unit is created it requires a module for each unit. Is it better to have 1 module that runs all units, or is it just fine to require a module for each unit? Also when a unit dies is there a way to stop the module to save memory?
I am requiring a module not cloning and making a new one. Also a bit curious why your in scripting support if you don’t script?
I just try to help if I can, that’s why.
Having multiple modules would cause very minimal if any lag.
Still, I’d recommend having just one.
It’s usually better to have one module for each type of unit, and you can save behavior in there.
If you have a synchronous while true
loop running to determine behavior for the unit, you can use a coroutine or spawn
to run in separate threads.
You can stop the module usually by having an interface for it. Like say you have your while true
loop from before, you would just make the loop check a boolean:
function module.Start(unit)
module.Enabled[unit] = true
while module.Enabled[unit] do
-- stuff
end
-- clean up code here
end
function module.Stop(unit)
module.Enabled[unit] = nil
-- or clean up code here
end
And if you have a connection to RunService
or another event, you can disconnect it:
function module.Start(unit)
module.Connections[unit] = RunService.Heartbeat:Connect(function()
-- stuff
end)
end
function module.Stop(unit)
if module.Connections[unit] then
module.Connections[unit]:Disconnect()
module.Connections[unit] = nil
end
-- clean up code here
end
This might not answer all your questions, but I hope it’s a start!