vrchat-community / UdonSharp

A compiler for compiling C# to Udon assembly
https://udonsharp.docs.vrchat.com
MIT License
463 stars 50 forks source link

VRCPlayerAPI happens a bug when I try to get force parameters of other players? #60

Closed cetusk closed 1 year ago

cetusk commented 1 year ago

Behavior

I wrote a code to get parameters of all joining players, including position and force. Something error happened when I try to get force parameters of other joining players, then all attached scripts will not work. No error for obtaining positions only, in constrast.

I want to dump error log using try / catch semantics but it's not supported..

My code ( essential part )

I commented "HERE" in the corresponding line.

    // I allocate a memory for storing all players at begin
    private VRCPlayerApi [] _players = new VRCPlayerApi [ 64 ];
    private int _numPlayers = 0;

    void Update ()
    {
       // get number of players and their contexts
        _numPlayers = VRCPlayerApi.GetPlayerCount ();
        VRCPlayerApi.GetPlayers ( _players );
    }

    private void _debugMsg ()
    {
        // process for current joining players
        for ( int j=0; j<_numPlayers; j++ )
        {
            // get a current player
            VRCPlayerApi player = _players [ j ];
            if ( player == null ) continue;

            // get geometric parameters of the current player
            int id = player.playerId;
            UnityEngine.Vector3 pos = player.GetPosition ();
            UnityEngine.Vector3 vel = player.GetVelocity ();
            UnityEngine.Vector3 rot = player.GetRotation ().eulerAngles;

            // HERE: get force parameters of the current player
            // float walkSpeed = player.GetWalkSpeed ();
            // float runSpeed = player.GetRunSpeed ();
            // float sideWalkSpeed = player.GetStrafeSpeed ();
            // float jumpStrength = player.GetJumpImpulse ();
            // float gravityStrength = player.GetGravityStrength ();

            // do something

        }
    }

Environment

MerlinVR commented 1 year ago

What's the issue? You cannot set player speed, jump, gravity, etc. on remote players, you can only set it on local players.

cetusk commented 1 year ago

@MerlinVR thanks a reply.

Currently I'm not grasping the error details. I only confirmed the attached scripts will stop ( players keep moving ).

Oh I didn't know I can't set ( and get also ? ) force parameters of remote players.


I tried to get position and force parameters, then draw its messages as a debugging view; I uploaded a snapshot when I were testing for alone. When a second player join in this world, the debugging is stop and no text messages are dumped.

https://user-images.githubusercontent.com/52586971/185833071-68ceb7ea-3adb-4ee5-a1fd-b43f8f827754.mp4

MerlinVR commented 1 year ago

You cannot set remote player settings. Getting remote player settings will probably return a local value that's not accurate. If your behaviour crashes it will print to the log.

cetusk commented 1 year ago

OK, I understood thanks. I will synchronize each local force parameters and distinct by a player index as an alternative.