[Netcode] Deferred messages were received for a trigger of type OnAddPrefab with key 227838193, but that trigger was not received within within 1 second(s).
UnityEngine.Debug:LogWarning (object)
Unity.Netcode.NetworkLog:LogWarning (string) (at ./Library/PackageCache/com.unity.netcode.gameobjects/Runtime/Logging/NetworkLog.cs:28)
Unity.Netcode.DeferredMessageManager:PurgeTrigger (Unity.Netcode.IDeferredNetworkMessageManager/TriggerType,ulong,Unity.Netcode.DeferredMessageManager/TriggerInfo) (at ./Library/PackageCache/com.unity.netcode.gameobjects/Runtime/Messaging/DeferredMessageManager.cs:97)
Unity.Netcode.DeferredMessageManager:CleanupStaleTriggers () (at ./Library/PackageCache/com.unity.netcode.gameobjects/Runtime/Messaging/DeferredMessageManager.cs:82)
Unity.Netcode.NetworkManager:NetworkUpdate (Unity.Netcode.NetworkUpdateStage) (at ./Library/PackageCache/com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs:82)
Unity.Netcode.NetworkUpdateLoop:RunNetworkUpdateStage (Unity.Netcode.NetworkUpdateStage) (at ./Library/PackageCache/com.unity.netcode.gameobjects/Runtime/Core/NetworkUpdateLoop.cs:192)
Unity.Netcode.NetworkUpdateLoop/NetworkPostLateUpdate/<>c:<CreateLoopSystem>b__0_0 () (at ./Library/PackageCache/com.unity.netcode.gameobjects/Runtime/Core/NetworkUpdateLoop.cs:287)
using UnityEngine;
using Unity.Netcode;
public class ProjectileLauncher : NetworkBehaviour
{
public GameObject projectilePrefab; // The projectile prefab to shoot
public Transform shootPoint; // The point where the projectile will be spawned
public float shootForce = 30f; // The force applied to the projectile
[SerializeField]
private GameObject orientation; // Direction from where to launch the projectile
private ulong ownerClientID;
private void Start()
{
// Get the client ID of the player who owns this object
ownerClientID = GetComponent<NetworkObject>().OwnerClientId;
Debug.Log("ProjectileLaucher OwnerClientID: " + ownerClientID);
}
public void ShootProjectile()
{
SpawnProjectileServerRPC();
}
[ServerRpc(RequireOwnership = false)]
private void SpawnProjectileServerRPC()
{
GameObject projectile = Instantiate(projectilePrefab, shootPoint.position, shootPoint.rotation);
projectile.GetComponent<NetworkObject>().SpawnWithOwnership(GetComponent<NetworkObject>().OwnerClientId);
Debug.Log("Projectile spawned with ownership for client ID: " + ownerClientID);
Rigidbody projectileRb = projectile.GetComponent<Rigidbody>();
if (projectileRb != null)
{
projectileRb.AddForce(orientation.transform.forward * shootForce, ForceMode.Impulse);
Debug.Log("Applied force to projectile Rigidbody.");
}
}
}
I used [ServerRpc] to spawn objects on the server, but the SpawnWithOwnership() is not spawning the object across the network.