Correct way to spawn server authoritative objects in Fusion?

Options
BlueKiwi
BlueKiwi
edited August 2022 in Fusion

Hello,

I am working on an ability system for my game with photon fusion. Essentially this requires players to spawn game objects as determined by game logic. I am wondering what is the correct way to implement this so it's completely server authoritative?

Basically I collect input as such:

if (GetInput(out ThirdPersonInputData inputData))
            {
                if (inputData.IsPressed(ThirdPersonInputData.LEFTCLICK))
                {
                    LeftClick = true;
                }
                else
                {
                    LeftClick = false;
                }

and have something like this on FixedUpdate

Something : NetworkBehaviour
{

public override void FixedUpdateNetwork()
        {
            base.FixedUpdateNetwork();
            HandleInput(); 


            if(LeftClick)
            {
               UseAbility(TestAbility, GetMyContext());
               
            }
        }


        public void UseAbility(UniversalAbilityTemplatePhotonFusion thisOperation, IAbilityContextPhotonFusion context)
        {
            if (!Object.HasStateAuthority) return;
            thisOperation.ExecuteOperationsPhotonFusion(context);
/*
ExecuteOperationsPhotonFusion(context)
...Stuff
context.Something.Runner.Spawn(stuff);

*/
        }

}


Where several down my effect is instantiated with Runner.Spawn by an object which does not inherit from NetworkObject, only has reference to the runner.

I can't shake the feeling that I am not understanding something about how Photon Fusion works and doing something wrong. For instance if I don't do the

if (!Object.HasStateAuthority) return;

The code still works fine I only get some weird null reference exceptions.


Or what's there stopping a potential cheater from decompiling and recompiling my game and giving himself authority to spawn gameobjects?


Anyone sanity check, please?

Comments

  • BlueKiwi
    Options

    Okay so this was answered on Discord by lukesta.


    Essentially I was really going insane and this is not the way to do this. The FixedUpdateNetwork together with NetworkInput ensure server authority and my weird nulls were from simulation on the client side going out of scope.