[Networked] not changed

The whole answer can be found below.

Please note: The Photon forum is closed permanently. After many dedicated years of service we have made the decision to retire our forum and switch to read-only: we've saved the best to last! And we offer you support through these channels:

Try Our
Documentation

Please check if you can find an answer in our extensive documentation on Fusion.

Join Us
on Discord

Meet and talk to our staff and the entire Photon-Community via Discord.

Read More on
Stack Overflow

Find more information on Stack Overflow (for Circle members only).

Write Us
an E-Mail

Feel free to send your question directly to our developers.

[Networked] not changed

Berlios1
2022-07-20 04:33:10

Hello! I'm not very strong in programming and I ask you to help me! And I use Google Translate to communicate. I can’t understand why my variable does not change. I have skills on Scriptblobj, and I try to assign the player "int" with the number of this card, so that then contact it. Having received a value, the server immediately replaces it, but if I connect to it, then I get the meaning, but I can’t change it. More precisely, it changes a couple of frames, judging by the log, but then again becomes the original

[Networked] public int skill1_element {get; set; } = -1;

Public Void Addskill (Int skill_int) // I call this function from another script

{

if (skill1_element == -1)

{

skill1_element = skill_int; // Here I try to assign this value Return;

}

}

Please tell me how to implement correctly. Fusion 105 read, but I can't understand how it works

Comments

OdoVR
2022-07-21 02:04:13

Hi @Berlios1

You may need to add a condition ensure your local Networked Object has input (or state?) authority before getting / setting the networked property.

eg...

[Networked] public int skill1_element { get; set; } = -1;

public override void FixedUpdateNetwork()

{

if (Object.HasInputAuthority)

{

Addskill(1);

}

}

public void Addskill(int skill_int) // I call this function from another script

{

if (skill1_element == -1)

{

skill1_element = skill_int; // Here I try to assign this value Return;

}

}

Hope this helps...

Berlios1
2022-07-21 03:03:23

OdoVR 2022-07-21T02:04:13+00:00

Hi @Berlios1

You may need to add a condition ensure your local Networked Object has input (or state?) authority before getting / setting the networked property.

eg...

[Networked] public int skill1_element { get; set; } = -1;

    public override void FixedUpdateNetwork()

    {

      if (Object.HasInputAuthority)

      {

        Addskill(1);

      }

    }

          

    public void Addskill(int skill_int) // I call this function from another script

    {

      if (skill1_element == -1)

      {

        skill1_element = skill_int; // Here I try to assign this value Return;

      }

    }

Hope this helps...

Hi, OdoVR    
Thank you for your response!    
I have a trigger that fires only if it's "Object.HasInputAuthority" and then runs this function to add the skill. Do I definitely need to change [networked] exactly in fixedUpdateNetwork() ?    

OdoVR
2022-07-21 05:24:32

@Berlios1 , I don't think you have to specifically use FixedUpdateNetwork(), I just placed that there as an example.

I'm pretty sure that you do have to handle both the writing (set) and reading (get) of the [Networked] property, similar to how you would Write / Read an OnSerializeView() stream in Photon (essentially, do I own the network object = write, if someone else owns it = read)

Please note I'm fairly new to Fusion also (coming from a PUN2 background) so my logic may not be completely correct. I'm just mirroring how I've used the [Networked] properties in my app.

Back to top