#@rpc function saying the input variable is the incorrect type, when it is correct .

1 messages · Page 1 of 1 (latest)

tidal sorrel
#

I have a script that is supposed to load a weapon scene as a child for the player. The function load_weapon() takes a resource containing the weapon scene and position information and uses it to create the child node containing the weapon. The resource class is pweaponres, which is forced by the function input.

When load_weapon() is called to swap weapons in game (loading during _ready() is fine), the peer swapping weapons works fine, but their opponent gets the error "cannot convert function from object to object" and the new weapon does not load. Both the function input and variable declaration are forced to have the class pweaponres, so I'm not sure what the problem is.

Also, when I change load_weapon() to accept any variable type, the client crashes when they connect. The client's error is (Error: E 0:00:07:317 pweaponrig.load_weapon: Invalid access to property or key 'SCENE' on a base object of type 'EncodedObjectAsID'.<GDScript Source>pweaponrig.gd:26 @ pweaponrig.load_weapon() <Stack Trace> pweaponrig.gd:26 @ load_weapon())

Does anyone know what the problem is?

script is attached below

unique night
#

I don't think passing resources as arguments over RPC really works (or at least not the way you expect it to). Hence the error you are seeing ( Invalid access to property or key 'SCENE' on a base object of type 'EncodedObjectAsID'.). You aren't getting a resource on your receiver, you're getting EncodedObjectAsID. It seems like maybe you could load the resource from this, but there are better ways.

Instead, you should send an ID or Enum of some sort to designate which weapon you are switching to, and then just load the weapon on the client (rather than expecting the full resource). Does that make sense?

limpid sorrel
tidal sorrel
#

Thank you guys!

#

I'll try sending the resource path instead, and set up a weapon id system at a later date

tidal sorrel
#

HOLY SHIT IT WORKS