Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Inquiry Regarding Netcode - Synchronizing Network Variables Across Different Projects

Discussion in 'Netcode for GameObjects' started by jvicogSpika, Nov 14, 2023.

  1. jvicogSpika

    jvicogSpika

    Joined:
    Dec 20, 2022
    Posts:
    6
    I am reaching out to seek assistance with a concern I am facing while working with Netcode for gameobjects in Unity.

    I am currently engaged in a project that requires separate versions for Android (URP) and PC (HDRP) due to specific technical requirements. Consequently, I have developed two parallel projects to accommodate these platform differences. Everything has been progressing smoothly until I encountered an issue with synchronizing Network Variables.

    The challenge arises from the fact that the Network Variable IDs do not match between the Android (URP) and PC (HDRP) projects. As a result, synchronization issues occur, preventing the Network Variables from functioning as intended.

    I would greatly appreciate any guidance or recommendations you could provide to address this situation. Whether there are best practices for handling such scenarios or specific procedures to ensure that Network Variable IDs align across different platform projects, any assistance you can offer would be invaluable.

    Thank you very much for your time and support
     
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,015
    The multi-project approach is generally tricky. I think the prefabs that you use need to be exactly the same in both projects. Meaning you cannot build them twice in two projects, you would have to create one in one project and then export it as .unitypackage and import it in the other project. That's most likely going to be required but I cannot be sure, I've never used two separate projects.

    The alternative would be to implement your own "variables" using just RPC calls.
     
  3. jvicogSpika

    jvicogSpika

    Joined:
    Dec 20, 2022
    Posts:
    6

    I have tried, but it still loses the reference and automatically assigns another ID.
     
  4. cerestorm

    cerestorm

    Joined:
    Apr 16, 2020
    Posts:
    639
    What CodeSmile suggested does work, at least for a simple test between two projects there are no issues. What is the Network Variable ID you're referring to?
     
  5. NoelStephens_Unity

    NoelStephens_Unity

    Unity Technologies

    Joined:
    Feb 12, 2022
    Posts:
    244
    As was mentioned about GlobalObjectIdHash value generation, having multiple projects will cause differences in the values generated. Also, you could run into issues if each project has prefabs that have more or less NetworkBehaviour components than the other (i.e. the NetworkBehaviorIds will be different) or the components are ordered differently.

    The core issue is how we come up with a unique identifier that, using the same project, will always generate the same GlobalObjectIdHash value. To do this, we use the GlobalObjectId that:

    I will look into using custom packages where one project handles the over-all editing of the assets in the package and another just adds it via package manager. This is something that I have not had a chance to test, but will look into the different possible ways one could share network prefabs.

    The biggest issue with a custom package is even though the network prefabs might have the same GlobalObjectIdHash value, any in-scene placed NetworkObjects will not.

    In the end, it might be easiest to keep everything under the same project and switch between render pipelines when needed.
     
  6. jvicogSpika

    jvicogSpika

    Joined:
    Dec 20, 2022
    Posts:
    6
    I am referring to the GlobalObjectIdHash. It is true that with a small test project it works correctly, but as more NetworkVariables are introduced and the scene intensifies the errors start.
     
  7. jvicogSpika

    jvicogSpika

    Joined:
    Dec 20, 2022
    Posts:
    6
    Thank you very much for your contribution. I will try the last solution you have proposed.