I’ve tried a simple network example where both client and server move a cube, which should be about as simple as it gets. What I have a hard time understanding, and this seems to be Unity-wide, is the initial movement lag. I’ve tried UNet, PUN and now Forge, and they all exhibit the same initial lag. For two instances running on the same PC (localhost), the initial message to move should, I think, be nearly instantaneous, but there is consistently a visible lag where the client (or host, if it’s the client that’s moving) cube lags by about half the width of the cube, and you can see it coasting to a stop after the host has stopped moving. I set up a similar test in UE4 and there is absolutely no visible lag, so I can’t figure it out what it is about Unity. Do anyone have any idea why this is happening?
If everything you tested got the same results. Did you not find it a bit odd?
Have you check your internet connection?
Many are using the network games, and
Yes, I found it very odd, which is why I tried with a different engine (UE4) but still on localhost, and if there was lag, it was imperceptible, whereas every solution that I tried with Unity has the same results. On localhost, outgoing packets don’t even have to go all the way down the OSI stack, so communications should be extremely fast, but with Unity, that initial message seems to be delayed. If you watch YouTube tutorials that also use a simple cube, you can see the initial lag there as well. I really (really) want to use Unity, but I can’t find a way past this.
I haven’t noticed any abnormal lag with UNet or Photon and have used both in production.
Hmmm, that’s how it should work, but the fact that I can see the same lag in online videos makes me believe that it is not my system. Any troubleshooting ideas?
Something in your Unity code? If it works with UE4, not your local internet. If it does not work in Unity with any network solution, more than likely something in your project. We use Unet without any problem and our scenes are more complicated than cubes. I will suggest to you what I do with my programmer…make a new Unity project, put in some simple stuff like capsules that move around, and then test it with Unet. If it works, then it is your original project. If not, then maybe a Unity bug…and you should report it.
Every project that I tried with Unity (UNet, PUN, Forge) all used new Unity projects, as were all of the online tutorials that I tried.
This is a link to a Forge Networking Remastered tutorial:
If you check out around 14:14 you’ll see what I mean. It’s fast, but when he moves the cube in the top left, you can see the slight hesitation in starting in the bottom two windows. UE4 does not have this delay and I can’t explain it.
Videos can sometimes slow things down, could it just be video lag? I know whenever I record something that moves, it always appears to lag. Try making a build and see what that does.
I followed the tutorial and copied what he did, and I got the exact same result ![]()
Why would you copy what he did if he had bad results? Try the profiler and see where you are getting spikes.
LOL, yeah, I guess the way I worded that sounds strange. I was following a series of tutorials to see what Forge Networking was like, and I like to follow along on my own because I find it helps me learn better. I’ve attached a Dropbox link to the project and I was wondering if you would mind trying it yourself. Run two instances (one can be in the editor, if you prefer) and make them windowed, 800x600 resolution, and if you have enough screen space, put one window above the other. Only the server can move its cube, so that will have to be the active window. When you move the server cube (A or D, or arrow keys) you should see a very distinct delay before the cube moves on the client screen, and it will continue moving on the client after it has stopped moving on the server.
https://www.dropbox.com/s/1xf2n9plbpddlro/Forge%20Networking%20Remastered.7z?dl=0
We do not use Forge so probably will not work on our server. But you might post this in the Forge thread and someone might be happy to help you. ![]()
That’s my point – it’s not just Forge. The following link is using Photon (PUN) and the author includes a couple of Gifs where the initial lag is obvious. In fact, he even comments on it and says it’s unavoidable due to network lag, which is the response that I usually get as well. Testing with UE4, however, doesn’t have that lag, but I’d really like to use Unity.
https://www.factorialcomplexity.com/blog/2017/07/17/introduction-into-photon-unity-networking.html
I see. Then you may have to use UE4. Good luck!
@Ben_Iyan This is because they use linear interpolation. Lerp is not suited for this. To get the perfect movement interpolation, you must use MoveTowards instead, and you also need to send the current speed of your object in addition to the position data. You can get the speed from the velocity using magnitude.
transform.position = Vector3.MoveTowards(transform.position, nextPosition, lastSpeed * Time.deltaTime);
@nxrighthere Yes, I agree, and that is how I do it. I have no problem with smoothly interpolated movement; the problem is the delay between movement starting on, lets say the host, and the movement of the networked version (e.g. a client). It’s almost as if Unity delays sending that first packet.
Does this happen only once after the object is spawned or does it occur every time the object starts moving?
Do you send data with the initial position at startup?
Every time the object starts moving, and I get it whether I’m using UNet, PUN or Forge, but nobody else seems to have this problem so I’m wondering if there’s a setting somewhere that I’m missing.
What version of Unity are you using? You tried to use different versions with a new clean project?
I’ve tried with 5.6, 2017.1 and now with 2017.2. Yes, I always started with a clean project. Each of the projects is from following a YouTube tutorial but I don’t think that would make a difference. I really appreciate the suggestions for things to try.