I am making a 2D RTS, and am trying to get a multiplayer version working. I've run into some problems with the order that scripts are getting executed. For the host everything runs fine, but when a new client connects, I get a lot of bugs. What's happening is that the objects that I've spawned already are getting loaded into the new client's scene before things they depend on, like the map itself. When I was writing the code, I was thinking that there's no way that something user-created could get get loaded before the map, because the map gets loaded right when game starts, but the order in which UNET loads spawned items seems to be weird like that.

Is there anything I can do to change this, or do I just need to rewrite things so that the loading of spawned items doesn't require the map to be loaded?


  • 1
    \$\begingroup\$ Is there a way to transfer an ordered list of objects to be spawned by client, so to force them to be created in the correct order? \$\endgroup\$ Jul 27 '17 at 16:59
  • \$\begingroup\$ As far as I know, that's deep beneath the hood of UNET. You've hit on the exact question I'm asking basically. \$\endgroup\$
    – elaid
    Jul 27 '17 at 17:29
  • 1
    \$\begingroup\$ If you are transferring the order correctly, what about the type of connection? With low level transport layer the quality of service can be defined as sending things in the correct order, reliably or unreliably. Is the issue that the network messages are sent unordered or unreliable? \$\endgroup\$ Jul 27 '17 at 17:32

Through some more experimentation, I think I've fixed the problem. The messages were all getting sent in the right order and getting received in the right order. The problem before was that the map wasn't networked, so it wasn't in that sequence of messages, and actually got started after all those messages were processed.

I ended up just making the map networked, which I should've done to start with anyway, so now it's the first thing that gets started, and the problem is solved.


The best way to create things in the correct order is to have a single point of entry, that is, a function that creates everything in order.

Also, if you have objects with cross-references, another option would be to create the objects first, and then create the references.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.