#ServerRpc not executing Unity NGO

1 messages · Page 1 of 1 (latest)

timid garnet
#

Hey all, back for another RPC related question.... again....

(NGO)
Anyways here's my problem this time. Essentially one player will have this script, and when they use their "ability" they will switch the positions of themself and the other player (or 2 other players). So I am trying to call this on the server with an Rpc, but of course I can't even get it to execute in the first place. I am only passing in the NetworkObjectReference struct, which literally says in the description that it CAN be used in RPCs. I set require ownership to false as well. This script is on the root of my player prefab which also has a ClientNetworkTransform and a NetworkObject , Rigidbody, and some other scripts that are unrelated and dont interact with this one. I don't know why this thing won't execute I feel like I have exhausted every possibility. I also tried a dummy ServerRpc with an int parameter and the prints still didn't run. They don't run on either client.

Here's the code

If you need to see more let me know, I could show the prefab but like I said all the network stuff is on the same object that this script is on. This prefab is also the default player prefab so its spawned by the NetworkManager not by me. Thanks to anyone who can help me here. It could just be the burn-out making me forget something obvious but idk.

hexed sail
#

The RPC has to be in a network behavior (and on a spawned network object) for it to run. Either AbstractAbility need to inherit Networkbehavior or you can move the RPC to another class that does.

timid garnet
#
using Unity.Netcode;
using UnityEngine;

public abstract class AbstractAbility : NetworkBehaviour, IAbility
{
    public abstract int Id { get; }
    public abstract int SortOrder { get; }
    public abstract float Cooldown { get; set; }
    public abstract string Name { get; }
    public abstract bool OnCooldown { get; set; }

    public abstract void Activate(IAbilityInteractable other);
}
timid garnet
#

is it because its abstract or something that it doesn't like it? I am so confused

hexed sail
#

That should work. As long as Shift is on a spawned network object.

timid garnet
#

Yeah I am losing my head over it. It is the default player prefab and gets spawned when the game starts. so why the hell is it not executing

#

anything i can like check to make sure?

hexed sail
#

Worst case scenerio, the RPC would be run locally when called. If its not running anywhere then something else is going on

timid garnet
hexed sail
#

The network object the script is on has to remain active. The script being disabled might cause issues when the RPC gets indexed. I'm not sure

timid garnet
#

print($"{IsOwnedByServer} {IsOwner} {IsClient} {IsSpawned}"); gave false true true true

#

Actually now that I am looking at it that is before disabling it. After re enabling it triggers OnNetworkSpawn again and outputs false false true true, but the rpc doesnt require ownership anyways hmm

hexed sail
#

The player Object is owned by the client but IsOwner doesn't seem to get properly set until after OnNetworkSpawn. I would [RPC(SendTo.Server)] and not deal with require ownership at all

Any process can communicate with any other process by sending a remote procedure call (RPC). As of Netcode for GameObjects version 1.8.0, the Rpc attribute encompasses server to client RPCs, client to server RPCs, and client to client RPCs. The Rpc attribute is session-mode agnostic and can be used in both client-server and distributed authority...

timid garnet