Improbable Icon

PositionReader.Authority Returning Wrong Value Whereas gameObject.GetAuthority<Position> is Correct

unity

#1

This issue only started very recently.

The check for PositionReader.Authority returns NonAuthoritative, but gameObject.GetAuthority<Position> returns Authoritative

Just thought I’d post something here for awareness!


#3

Hi @basil,

Thanks for reporting this. Could you give me some more context for the project setup that lead to you seeing this happen? Is the worker that should be authoritative over the position actually the one that is getting authority? And if so, why is this worker using a PositionReader instead of a writer?


#4

No problem @Kevin!

This on a HealthReader object. The Writer is owned by the server, but the Position Writer is owned by the client. The implementation is inside of the got_hit event handler, and is a check for position-authority to show the hit player an effect for getting hit.

It was something like:

void GotHit(HealthResponse request) {
        if (gameObject.GetAuthority<Improbable.Position>() == Improbable.Worker.Authority.Authoritative) {
            
            // Damage dealt from hit. More damage = more intense damage indicator
            int damage = request.damage;
            
            // Position in World Space from which you got hit
            Vector3 position = request.shooterPosition.ToUnityVector();
            
            // Show damage indicator
            player.GetComponent<DamageIndicator>().ShowDamage(position);
        }
    }

It’s implemented with the reader because I anticipate adding an effect to show other players that a particular player just took damage.


#5

Hi @basil,

Just to confirm how you are determining that PositionReader.Authority and gameObject.GetAuthority are returning different values, are you saying that if you log gameObject.GetAuthority from within that if statement it would sometimes return something other than Authoritative? If not, how else are you verifying this?


#6

A couple weeks ago, PositionReader.Authority was always returning the correct Authority, but is now stuck on saying Not Authoritative.

That’s when I discovered gameObject.GetAuthority, which seems to always be correct.


#7

And to confirm, if you print these one line after the other in the same place, they are returning different results?

(sorry for needing to confirm this all, this just strikes me as very strange)