#Spawning entities

1 messages · Page 1 of 1 (latest)

solar glacier
#

i searched online but it seems like I just do the normal instanciate to add objects to the scene but for some reason it doesn't seem to work
And yes I do have the network object script attached to it

lean pelican
solar glacier
#
    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?

lean pelican
solar glacier
#

notlikethis 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

lean pelican
#

You could send the position in the client rpc parameters

solar glacier
#

fair nuff

#

thanks

solar glacier
#
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

lean pelican
#

Or you can sync the Item ID's in a networklist/RPC

solar glacier
#

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 🙏🏻

lean pelican
#

You posted random non networked code and asked how to sync a list. The answer is in the docs

solar glacier
#

Yea appreciate it and yea my dumbass forgot to make them NetworkBehaviors

solar glacier
#

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

lean pelican
#

Should probably make a separate thread for that but you use the Unity Lobby service or Sessions API if you are using Unity 6

solar glacier
#

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

lean pelican
lean pelican
solar glacier
#

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

lean pelican
lean pelican
#

Relays services allow you to connect clients without Dedicated Servers and let you bypass NAT firewalls for player hosted servers