I’m new to fishnet and trying to get things going. I already have client and server running and can spawn items on the server. But in my 3D VR application I have a 3D UI that is local only. In 1P mode when you press a button it instantiates an object for you. I was trying to recreate that with RPCs, but that doesn’t seem to work because my 3D button is not a networkobject. So everying comes back null when I try to make the call. I tried referencing the network manager that lives on my gamemanager but that can’t find the remote call. Is this even possible or do I have to make my UI some kind of shared object? I did try just attaching the network object to it but that made it invisible (I assume because it was not spawned by the server). Thank you.
Hi there, you can use Broadcasts to send messages from non network objects. Or you could have a single network object to send you rpcs from, it doesn’t have to be on the UI game object. It can even be a global object.
Alright I’m trying this but the message from client to server doesn’t come through. Not sure yet how do dig through and debug this but I’m looking. Did I miss something? Client and server are connected (my client sees a test spawn I do at startup).
On the client I have:
public class Vend : NetworkBehaviour
{
public GameObject VendingMachine;
public GameObject itemPrefab; // Reference to the prefab
private GameObject padObject; // The PAD object on which the item will be placed
public struct VendBroadcast : IBroadcast
{
public string prefabName;
public Vector3 padPos;
}
Debug.Log("Pad name: " + itemPrefab.name + " Position: " + padObject.transform.position);
VendBroadcast msg = new VendBroadcast()
{
prefabName = itemPrefab.name,
padPos = padObject.transform.position
};
InstanceFinder.ClientManager.Broadcast(msg);
and on the server side:
private void OnVendRequest(NetworkConnection conn, VendBroadcast msg, Channel channel)
{
Debug.LogError($“Vend Request Received ‘{msg.prefabName}’”);
// Check if the item name exists in the prefab dictionary
if (prefabDictionary.TryGetValue(msg.prefabName, out GameObject itemPrefab))
{
// Instantiate the object on the server
GameObject vendedItem = Instantiate(itemPrefab, msg.padPos, Quaternion.identity);
NetworkObject networkObject = vendedItem.GetComponent();
if (networkObject != null)
{
// Spawn the object on all clients
ServerManager.Spawn(networkObject);
// Notify the specific client that requested the spawn so it can adjust the object
//TargetAdjustClientObject(conn, networkObject.ObjectId);
}
}
else
{
Debug.LogError($"Item '{msg.prefabName}' not found in the prefab dictionary.");
}
}
private void OnEnable()
{
InstanceFinder.ServerManager.RegisterBroadcast(OnVendRequest);
}
private void OnDisable()
{
InstanceFinder.ServerManager.UnregisterBroadcast(OnVendRequest);
}