Skip to content
This repository has been archived by the owner on Aug 15, 2022. It is now read-only.

Fields skipping dirty check #73

Closed
BrianWiz opened this issue Aug 21, 2017 · 4 comments
Closed

Fields skipping dirty check #73

BrianWiz opened this issue Aug 21, 2017 · 4 comments
Labels

Comments

@BrianWiz
Copy link
Contributor

BrianWiz commented Aug 21, 2017

Version Number and Operating System(s):

v24 and Windows 10

EDIT:
v24.1, Windows 10, Unity 2017.1.0f3

Expected behavior:

Fields send only when they're dirty

Actual behavior:

Fields are sending every update interval even if never changed

Steps to reproduce:

Tested by running a field change event

   protected override void NetworkStart()
   {
      base.NetworkStart();
      networkObject.positionChanged += PositionChanged;
   }
   private void PositionChanged(Vector2 position, ulong test)
   {
        MainThreadManager.Run(() =>
        {
            Debug.Log("test");
        });
   }

[Optional] Discord Username:

NoMercy

@BrianWiz
Copy link
Contributor Author

BrianWiz commented Aug 24, 2017

@baflink
I've tested with the latest commit and something still isn't right. It seems like field change events now fire if an RPC is sent from the client. Though I can't quite tell for sure, but I'm pretty sure that's what's happening. Or maybe it's receiving any field updates from the server causing them to fire?

For example I have a uint, I set it once on the server and only once, yet when I move, it's change event seems to fire, I've done a find in all files to double check I'm not setting it anywhere else.

I'll keep investigating.

EDIT:
Yeah, I'm pretty sure it's when another field(s) is updated, it fires the event for every field, even fields that haven't been updated.

@BrentFarris
Copy link
Member

@BrianWiz Can you try with the newest NetworkObjectTemplate.txt on develop?

@BrianWiz
Copy link
Contributor Author

BrianWiz commented Sep 3, 2017

@baflink Finally got around to testing this. There is still a problem.

I've got two fields, one is "position" (Vector2), one is "test" (int), both have Interpolation off. I set test once in NetworkStart(), and I set position in Update();

The result is that the testChanged event fires every time position is changed. So it looks like if any field is changed, it thinks they all changed. I confirmed this by commenting out the line that sets the position in Update();

Here's my entire class(es) so you know I'm not doing anything weird.

using UnityEngine;
using BeardedManStudios.Forge.Networking;
using BeardedManStudios.Forge.Networking.Unity;
using BeardedManStudios.Forge.Networking.Generated;

public class Grenade : Projectile
{
    protected override void NetworkStart()
    {
        base.NetworkStart();

        if (networkObject.IsServer)
        {
            networkObject.test = 2;
        }
        else
        {
            networkObject.testChanged += TestChanged;
        }
    }

    void Update()
    {
        if (networkObject != null)
        {
            if (networkObject.IsServer)
            {
                networkObject.position = transform.position;
            }
        }
    }

    private void TestChanged(int test, ulong timestamp)
    {
        Debug.Log("test");
    }
}

using UnityEngine;
using BeardedManStudios.Forge.Networking;
using BeardedManStudios.Forge.Networking.Unity;
using BeardedManStudios.Forge.Networking.Generated;

public class Projectile : ProjectileBehavior
{

	// Use this for initialization
	void Start () {
		
	}
	
	// Update is called once per frame
	void Update () {
		
	}

    public virtual void MoveProjectile(Vector3 direction)
    {
      //  GetComponent<Rigidbody>().AddForce(direction * force, ForceMode.Impulse);
    }
}

@BrianWiz
Copy link
Contributor Author

BrianWiz commented Sep 4, 2017

@baflink So it looks like on the server, in SerializeDirtyFields(), it returns dirtyFieldsData with fields that shouldn't actually be dirty.

So it looks like if any field is dirty, it sends them all of them over in HeartBeat() on NetworkObject.cs. If none are dirty, it doesn't send anything as expected.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants