Search Unity

[MLAPI] Establish a basic LAN connection

Discussion in 'Netcode for GameObjects' started by BigKahuna311, May 4, 2021.

  1. BigKahuna311

    BigKahuna311

    Joined:
    Sep 9, 2019
    Posts:
    5
    Hello,

    I'm giving MLAPI a try (I've made a few single-player games, but I've never delved into multiplier) and I'm trying to start with a very basic LAN connection. I've got two copies of my project running, each one has a singleton NetworkManager with UNET Transport as the NetworkTransport. Each NetworkManager also has a default player prefab loaded in which includes the NetworkObject component. I start the host, and it spawns in the first player in the first instance. I start the client and it spawns in the second player in the first instance and loads both players into the second instance. The catch is that these two instances are entirely separate. Any player movement/procedural generation/enemy generation is completely unique to each instance. They both occupy the same scene but different instances of it or so it seems. How come both the client and the host don't seem to be in the same version of the scene if the host recognizes that the other client has connected. Am I missing something obvious? Let me know if I need to provide context or screenshots if my problem hasn't been described clearly. I'm not very familiar with net code jargon.

    Thanks!
     
  2. BigKahuna311

    BigKahuna311

    Joined:
    Sep 9, 2019
    Posts:
    5
    After some research... are these actually two separate scenes with two separate scripts generating random events/patterns that need to be synced and sent to the server then distributed to each client? And if this is what I in fact need to do how do I go about that using MLAPI? I'm not seeing too many tutorials since it seems to be so new.
     
  3. luke-unity

    luke-unity

    Joined:
    Sep 30, 2020
    Posts:
    306
    MLAPI by default does not synchronize anything in your scene such as movement/procedural generation/enemy generation etc. You have to use the built in MLAPI components to synchronize that. For movement you can just add a `NetworkTransform` component to your GameObject.

    I can recommend to read through some of the documentation pages for MLAPI to learn about all our components:
    https://docs-multiplayer.unity3d.com/docs/getting-started/about-mlapi
     
    BigKahuna311 likes this.
  4. BigKahuna311

    BigKahuna311

    Joined:
    Sep 9, 2019
    Posts:
    5
    Ah... and it seems like if I wanted a stationary object replicated (e.g. a wall) I would add a Network Object component. Seems cool, I'll give it a shot. I can't believe I overlooked something so massive!

    Thanks,
    Ryan