#Add Entity Component via RPC

1 messages · Page 1 of 1 (latest)

tidal girder
#

Is there a way to add Entity Components in a generic way? I'm trying to achieve an RPC call that will say "Hey, add this entity component to this ghost entity"

Right now I'm just making specific RPCs that will do it, but I'd like to be able to send something like a string and the receiver would add it that way. Only way I can think of is by using reflection on the receiving end.

mint garnet
#

You could send the ComponentType index. Although It's possible that you'd need to obtain the StableTypeHash of that ComponentType and use that.

odd token
#

Luis gomez is right on with how you can do this (i'd suggest stable hash just to be sure)
Though what you suggest is actually pretty dangerous

#

What stops a malicious actor just telling the server to add an invulnerability component to their character

#

Or to add an isdead component to an opponent

mint garnet
#

I think that's more about the server logic. You could just ignore messages from unauthorized sources. But indeed is something to think about, and be careful

icy jasper
#

Yeah, this is server->client RPC. Oh I see, you're thinking about someone hacking the server.

#

What does it mean to obtain the StableTypeHash of a ComponentType?

mint garnet
#

The StableTypeHash is the "code" used to identify a ComponentType in a deterministic way. The ComponentType index is not stable between editor and build and because I don't fully understand in which cases is stable, I'm suggesting to consider using StableTypeHash instead.

You can get StableTypeHash like this

TypeManager.GetTypeInfo(componentType.TypeIndex).StableTypeHash

mint garnet
magic swift
#

Note that replication will not work if you add replicated components at runtime (because NetCode won't know it needs to serialize these new components).

If you do want to create dynamic ghosts at runtime, it's a little more involved. See: https://forum.unity.com/threads/about-ghost-spawning-and-components-synchronization.1488807/

icy jasper
#

The components I want to add are not ghost components, but thanks for the info. I didn't think it was possible at all to add ghost components at runtime.