#null exception when spawning
1 messages · Page 1 of 1 (latest)
im not sure... The error shows up from a unity networking script when I press the button to spawn
the button itself has a network object component tho:
Post the entire error
Unity.Netcode.NetworkMetrics.GetObjectIdentifier (Unity.Netcode.NetworkObject networkObject) (at ./Library/PackageCache/com.unity.netcode.gameobjects/Runtime/Metrics/NetworkMetrics.cs:527)
Unity.Netcode.NetworkMetrics.TrackRpcSent (System.UInt64 receiverClientId, Unity.Netcode.NetworkObject networkObject, System.String rpcName, System.String networkBehaviourName, System.Int64 bytesCount) (at ./Library/PackageCache/com.unity.netcode.gameobjects/Runtime/Metrics/NetworkMetrics.cs:342)
Unity.Netcode.LocalSendRpcTarget.Send (Unity.Netcode.NetworkBehaviour behaviour, Unity.Netcode.RpcMessage& message, Unity.Netcode.NetworkDelivery delivery, Unity.Netcode.RpcParams rpcParams) (at ./Library/PackageCache/com.unity.netcode.gameobjects/Runtime/Messaging/RpcTargets/LocalSendRpcTarget.cs:52)
Unity.Netcode.ServerRpcTarget.Send (Unity.Netcode.NetworkBehaviour behaviour, Unity.Netcode.RpcMessage& message, Unity.Netcode.NetworkDelivery delivery, Unity.Netcode.RpcParams rpcParams) (at ./Library/PackageCache/com.unity.netcode.gameobjects/Runtime/Messaging/RpcTargets/ServerRpcTarget.cs:86)
Unity.Netcode.NetworkBehaviour.__endSendRpc (Unity.Netcode.FastBufferWriter& bufferWriter, System.UInt32 rpcMethodId, Unity.Netcode.RpcParams rpcParams, Unity.Netcode.RpcAttribute+RpcAttributeParams attributeParams, Unity.Netcode.SendTo defaultTarget, Unity.Netcode.RpcDelivery rpcDelivery) (at ./Library/PackageCache/com.unity.netcode.gameobjects/Runtime/Core/NetworkBehaviour.cs:399)
PlayerController.SpawnFireballRPC (System.Single x, System.Single y) (at Assets/PlayerController.cs:62)
PlayerController.Fireball () (at Assets/PlayerController.cs:56)
UnityEngine.Events.InvokableCall.Invoke () (at <44f3679c53d1477a9c6e72f269e3a3a9>:0)
UnityEngine.Events.UnityEvent.Invoke () (at <44f3679c53d1477a9c6e72f269e3a3a9>:0)
UnityEngine.UI.Button.Press () (at ./Library/PackageCache/com.unity.ugui/Runtime/UGUI/UI/Core/Button.cs:70)
UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) (at ./Library/PackageCache/com.unity.ugui/Runtime/UGUI/UI/Core/Button.cs:114)
UnityEngine.EventSystems.ExecuteEvents.Execute (UnityEngine.EventSystems.IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at ./Library/PackageCache/com.unity.ugui/Runtime/UGUI/EventSystem/ExecuteEvents.cs:57)
UnityEngine.EventSystems.ExecuteEvents.Execute[T] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.ExecuteEvents+EventFunction`1[T1] functor) (at ./Library/PackageCache/com.unity.ugui/Runtime/UGUI/EventSystem/ExecuteEvents.cs:272)
UnityEngine.EventSystems.EventSystem:Update() (at ./Library/PackageCache/com.unity.ugui/Runtime/UGUI/EventSystem/EventSystem.cs:530)
did I set the RPC wrong ?
is the fireballPrefab in the spawnable objects list?
yes
Are you destroying anything on the player object after it's spawned?
no
ohh hold up, I have a script from the docs that I copy pasted that makes it not server authorative...
using Unity.Netcode.Components;
[DisallowMultipleComponent] // Prevents you from adding the ClientNetworkTransform to the object more than once.
public class ClientNetworkTransform : NetworkTransform
{
/// <summary>
/// Used to determine who can write to this playerTransform. Owner client only.
/// This imposes state to the server. This is putting trust on your clients. Make sure no security-sensitive features use this playerTransform.
/// </summary>
protected override bool OnIsServerAuthoritative()
{
return false;
}
}
im changing the rpc to send to clientandhost instead
maybe thatll do something
That won't work
ur right lol
it shouldnt be sendtoserver anyway tho right? Since the topology is clienthosted, and I have that script from the unity docs to make it so im assuming. The host would act as the server, would send to server = send to host in this instance ?
Host = Client + Server
There’s nothing wrong with your spawning code. You would get different errors for that
I’ve never seen the error you’re getting, there’s something else that you must be doing that’s off
The button should not be networked
i was thinking it'd be weird to have every button be networked since that just seems inneficient. But I was following a code monkey tutorial and they mentioned with RPCs u want the object to have a network object component, the derived from NetworkBehaviour in the script, and the RPC header thing, I thought that first part he mentioned might have been something I needed to do for the button since its from the Event onclick
i didnt add it at first, it was just a troubleshooting thing i added afterward just in case
but its still not working :C
This is the playerprefab's inspector, is there something im missing from the network object and transform components ?
fireball prefab
ive tried the 2 different authoirty modes, owner and server but no luck
be sure to remove the network object from the button. How is the button referencing the player object?
through the prefabs player controller script, calls Fireball() which itself calls the fireballRPC with the given x, and y
and network object from the button removed 🫡
thats the structure code monkey used anyway in his example. Player's script calls a function that calls an RPC. Although his was an on mouse click event and mines a button click.
im assuming I cant directly put the RPC on the button click, but i doubt thats the issue anyway
alright I added some debugs, apparently the RPC is being called from something without ownership ?
public void Fireball()
{
if (fireballPrebab == null)
{
Debug.LogError("Fireball prefab is not assigned!");
return;
}
if (!IsOwner)
{
Debug.LogError("FireballRPC() called from a non-owner player!");
return;
}
SpawnFireballRPC(finalPosition.x, finalPosition.y);
}```
How are you assigning this in the inspector when the player is not in the scene yet?
... is this one of those "u cant do this with a prefab " things owo
i dragged the prefab of the player into it from the assets folder , I can't do that ?
ig this is where the GameManager comes into play
The button has no way of knowing which player prefab it's for.
You need to assign the button listener in code when the local player spawns in
