Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

Sync Data from client to server (weird thing is happening)

Discussion in 'Multiplayer' started by mudibushnaq, Jul 5, 2018.

  1. mudibushnaq

    mudibushnaq

    Joined:
    Dec 16, 2012
    Posts:
    55
    so i have two units that are fighting and they have :
    Health
    Max Health
    Move Speed
    Attack Damage
    and all of them are commented with [SyncVar] so they can be synced if they changed .
    and i use NetworkSpawn to spawn the units and Command from client .

    everything is synced great and good. but i have a function that upgrades the unit so it adds more health , MaxHealth , MoveSpeed and Attack Damage.
    and i have 4 Types of units and all of them WORKS GREAT expect one unit and this unit has the most health and max health .

    so in this first picture :

    Upgrade 1:


    the info is shown the MaxHealth for this unit is
    300 Health and when i click the upgrade button it will increase the champion health by 50 so the next time i spawn it , it will have 350 Health and 350 MaxHealth.

    Upgrade 2:


    so as you can see when spawning the next unit it will have MaxHealth 350 and health with 350
    Health = MaxHealth when first spawned.

    On Upgrade 3 problems starts (for this unit only):

    Upgrade 3:


    here you can see that the host (server) got the old HP which is
    350 and added 150 Health so it must be 450 for MaxHealth and Health
    but for client it is
    400
    so why its 400 ? let's guess why , the base health for this unit is 300 , so it got the base health (i don't know why) and then upgraded it and added the Upgrade number 3 Health (100) then it became 400 and not 450
    but it should get the older Health (which is 350) and then add 100 (upgrade 3 health) and the unit total health must be 450 as in the host .


    * so i am more interested and this sounds weird becouse other units works great with the upgrades and health sync ! only this unit is not working and after getting more than 450 health .
    * i tried to reduce the next upgrade health for each upgrade from (50/100/150) to (25/25/25) and it worked !

    health is the weird thing that it works great for all units expect this one that has 3 Upgrades (50/100/150) .
    other units got (10,10,25) and they work GREAT !

    im so confused
     
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    You've explained the symptoms, but not how you actually implemented anything. But I'm going to make a guess based on your thread title "Sync Data from client to server". SyncVar's sync values from the server to the clients. They do not sync from the clients to the server. If you change the value of a SyncVar on a client, only that client will ever see that change. Generally you should never update the value of a SyncVar on a client unless you're doing so inside a SyncVar Hook function, otherwise you're going to end up with out of sync values.

    If you need to update a SyncVar from a client, you send a Command or a Message to the server to tell the server to make that change.

    If that isn't the issue, please post the relevant code that covers everything you mentioned you're doing. Don't forget to use CODE tags on the forum.
     
  3. mudibushnaq

    mudibushnaq

    Joined:
    Dec 16, 2012
    Posts:
    55
    thank you for the answer , i have solved the problem by removing the syncvar S*** thing
    and now i just use commands and rpc to update anything from client to server or from server .
    after i knew that syncvar only syncs from server to client and thats why i used to get out of sync vars and HP ints .

    thank you very much