How do I despawn NetworkObject with no stateAuthority (Shared Mode)
The whole answer can be found below.
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).
How do I despawn NetworkObject with no stateAuthority (Shared Mode)
SlattBurger
2022-08-23 20:26:00
Hello,
How do I despawn NetworkObject that has been in the scene before joining? I have tried calling Runner.Despawn() from MasterClient but it does not works.
Comments
Isaac_Augusto
2022-08-24 11:36:08
Hi,
This should be the correct approach, since the MasterClient has state authority over the scene objects.
Do you get any console errors? How are you despawning the Object? Could you provide the code snippet? What Fusion SDK version are you using? Could you try again with the last nightly?
Isaac Augusto
Photon Fusion Team
SlattBurger
2022-08-24 16:09:39
Hello,
No, I do not get any console errors.
I am calling Runner.Despawn() from MasterClient"
Code:
private void Update() => PickUpItemHandler();
private void PickUpItemHandler()
{
Ray ray = GetComponentInChildren().ScreenPointToRay(new Vector2(Screen.width / 2, Screen.height / 2));
if (Physics.Raycast(ray, out RaycastHit hit))
{
PickupableItem pItem = hit.collider.GetComponentInParent(); if (pItem && Input.GetKeyDown(KeyCode.F))
{
print($"Object's authority = {pItem.GetComponent().StateAuthority}"); // prints "[Player:None]"
print($"State authority is LocalPlayer = {pItem.GetComponent().StateAuthority == FindObjectOfType ().LocalPlayer}"); // prints "false"
print($"LocalPlayer is MasterClient = {FindObjectOfType().IsSharedModeMasterClient}"); // prints "true" FindObjectOfType
().Despawn(pItem.GetComponent ());
}
}
}I am using 1.1.1 Stable
No, it still does not works on 1.1.2 Nightly
I have also tried to do the same thing with object that was spawned by this player and it works fine.
Is there any option that would allow clients to destroy object without stateAuthority over that object?
Isaac_Augusto
2022-08-25 14:43:24
Hi,
Despawn() and Spawn() shouldn't be called outside Fusion loops (FixedUpdateNetwork, Runner callbacks, etc) to prevent unexpected behaviours, please try the same in FixedUpdateNetwork
instead of Update
.
Is there any option that would allow clients to destroy object without stateAuthority over that object?
No, that would be against the idea of the state authority.
Isaac Augusto
Photon Fusion Team
SlattBurger
2022-08-26 18:23:30
Found out I got this error because NetworkObject I was trying to destroy was not registered in NetworkRunner, so my problem is solved. Thank you for your time.
Back to top