#Spawning entities
1 messages · Page 1 of 1 (latest)
only the host/server can spawn objects. It will need to instantiate the object then call .Spawn() on it
https://docs.unity3d.com/Packages/com.unity.netcode.gameobjects@2.6/manual/basics/object-spawning.html
public void damage(float damage)
{
if (!IsServer) return;
health.Value -= damage;
seeDmgClientRpc();
if (health.Value <= 0)
{
respawn();
}
}
void respawn()
{
transform.position = Vector3.zero;
health.Value = maxHealth.Value;
}
[ClientRpc]
void seeDmgClientRpc()
{
Debug.Log(health.Value);
}
even tho this is being run on the server why is it that only when i put the transform position on the code in the client rpc
it works
otherwise it doesnt
or partially does like does work on host player but not on client player or something like that
also damage is called by a function which is a serverRPC
is it cuz each player is a owner of itself
but why should the host take priorty over the owner?
ClientRPCs can only be sent by the host/server and broadcast to the other clients.
https://docs.unity3d.com/Packages/com.unity.netcode.gameobjects@2.6/manual/advanced-topics/message-system/rpc.html
thats not what i meant
public void damage(float damage)
{
if (!IsServer) return;
health.Value -= damage;
if (health.Value <= 0)
{
respawn();
}
}
void respawn()
{
health.Value = maxHealth.Value;
locationClientRpc();
}
[ClientRpc]
void locationClientRpc()
{
transform.position = Vector3.zero;
}
this seems to work but this is gross
You could send the position in the client rpc parameters
public class InventoryManager : MonoBehaviour
{
public InventoryItem[] items;
public InventoryItem GetItemFromSlot(int slot)
{
return items[slot];
}
public void AddItemToInv(InventoryItem item)
{
items.Append(item);
}
}
public class Spike : MonoBehaviour
{
private bool isPlanted = false;
void OnCollisionEnter(Collision collision)
{
if(collision.collider.GetComponent<Health>() != null && collision.collider.GetComponent<Health>().getHealth() > 0 && !isPlanted)
{
collision.collider.GetComponent<InventoryManager>().AddItemToInv(GetComponent<ItemObject>().item);
Destroy(gameObject);
}
}
}
how do i sync my inv over the network
i tried using RPC's but didnt work tried to make AddItem func a Client RCP still cant seem to figure it out
Make your Items an INetworkSerializable struct and you can use a NetworkList
Or you can sync the Item ID's in a networklist/RPC
No offense im really greatful for your help and support but pls stop spamming docs for everything 😭 , also the issue was that i was using Append which doesnt do anything so i made it a list and used .Add and made it a client RPC and made the collision logic on isServer exclusive
again no offense 🙏🏻
You posted random non networked code and asked how to sync a list. The answer is in the docs
Yea appreciate it and yea my dumbass forgot to make them NetworkBehaviors
okay so im at the point where i did the basic gameplay now the thing is i want to make a lobby then start a game with certain players
how should i go about that
Should probably make a separate thread for that but you use the Unity Lobby service or Sessions API if you are using Unity 6
How does this seperate thread stuff work?
Okay I looked at unity lobby service it seems like it's something that runs on unity servers what if I want to do it purly on my own
You just make a new post in #1390346492019212368
If you want to roll your own lobby service then you are looking at writing your own web service backend as well as a global server infrastructure.
Okay i looked at unity relay
Seems like something I can use
Then about the web backend im pretty good with backend not sure where to start connecting it with unity tho
And also relay seems like it connects different devices how do big games like Fortnite do it cuz it's not a direct connection
And i doubt they have a billion devices running each match
Epic probably does.
For Web Services you use Unity WebRequests to access them. For Dedicated Servers you can connect to them directly through IP addresses.
Relays services allow you to connect clients without Dedicated Servers and let you bypass NAT firewalls for player hosted servers