News UnrealEd Files Mods FragBU Liandri Archives
BeyondUnreal Forums

Go Back   BeyondUnreal Forums > Unreal Development > Coding

Reply
 
Thread Tools Display Modes
Old 15th Nov 2004, 10:03 AM   #1
TheSoepkip
Registered User
 
Join Date: Nov. 15th, 2004
Posts: 3
[UT2K4 Replication] Objects as parameters in replicated functions

Hello everyone,

Once again a question about replication... I've read several replication docs out there but I still find it difficult to get from the theory to a working application. I was hoping someone could enlighten me by pointing out my mistakes and perhaps provide or point me to a working or similair example.

The situation: I've some code in which players can form teams. A player can send an 'invite' to another player. The other player can either accept or decline the invitation. Upon accepting the invitation, the other invitee is added to the team object of the inviter. Everything works up to the point where the sever is to tell the invitee what his new team looks like. The latter is displayed in the HUD. I've tried this using function which more or less looks like this:

"setTeam(Team newTeam)"

This function is called from a pawn which is the baseclass of the pawn used by the playercontroller. When add some logs to the application, I get the following output:

[server] setTeam( package Base.Team );
[client] setTeam( none );

Because of this I concluded it's not possible to call client methods with objects as parameters. Is this correct and could someone explain why the team object 'disappears' ?

Thanks,
TheSoepkip is offline   Reply With Quote
Old 16th Nov 2004, 04:20 AM   #2
Mychaeel
 
Join Date: Oct. 3rd, 2001
Location: Frankfurt/Main, Germany
Posts: 3,829
It is perfectly possible to pass object references in replicated functions, but doing so doesn't automatically replicate the referenced object itself. If, in your case, that TeamInfo actor doesn't happen to be replicated to the client at the time the function is called, the client will receive a "None" reference instead of a valid TeamInfo reference.

However, since TeamInfo is derived from ReplicationInfo, it should be replicated to clients. Maybe you're just dealing with a timing problem here because you're calling your function too soon after spawning the TeamInfo actor.
Mychaeel is offline   Reply With Quote
Old 16th Nov 2004, 06:13 AM   #3
TheSoepkip
Registered User
 
Join Date: Nov. 15th, 2004
Posts: 3
Thanks for the reply Mychaeel.

I wasn't clear on this. The team object I'm referring to is "just" an Object, it's not an object of the TeamInfo class from unreal script.

I have some experience with other game engines, which is both an advantage and disadvantage ... The last engine I worked with passed objects as an id, which basically implied that as long as the object exists on both server and client you can pass it without any problems. I am more or less expecting Unreal to work the same way, which it obviously isn't

I've tried wrapping it into a ReplicationInfo, but that didn't seem to work; in fact it only made it worse so to say. Perhaps I'm approaching this the wrong way ... that's why I asked if perhaps someone had an example of using the replicationinfo.
TheSoepkip is offline   Reply With Quote
Old 16th Nov 2004, 10:33 AM   #4
Mychaeel
 
Join Date: Oct. 3rd, 2001
Location: Frankfurt/Main, Germany
Posts: 3,829
Quote:
Originally Posted by TheSoepkip
I wasn't clear on this. The team object I'm referring to is "just" an Object, it's not an object of the TeamInfo class from unreal script.
Objects of classes not derived from Actor don't work with replication; all the native replication magic is in Actor. Thus, since your object cannot be replicated to the client, passing a reference to it from server to client won't do any good -- even if the client receives some sort of unique object identifier (which it probably does), there's no corresponding object on the client to point it to.

Quote:
The last engine I worked with passed objects as an id, which basically implied that as long as the object exists on both server and client you can pass it without any problems.
There's the point: Your object doesn't exist on both server and client. Only Actor-derived objects can do that trick.

Quote:
I've tried wrapping it into a ReplicationInfo, but that didn't seem to work; in fact it only made it worse so to say. Perhaps I'm approaching this the wrong way ... that's why I asked if perhaps someone had an example of using the replicationinfo.
ReplicationInfo is merely an Actor subclass with some replication-related default properties conveniently set; there's no special magic in ReplicationInfo. (Actually, you can look at the ReplicationInfo source code to see which properties are set there -- you could do the same with any Actor-derived class.)

If you want to pass structured information from server to client, maybe you should consider using a struct instead of an object. Structs are passed by value (instead of by reference), so you can safely pass them through a replicated function as long as their size doesn't exceed a certain limit (about 384 characters total for all function parameters, I think). If your struct contains references to objects, the limitations mentioned above apply for those too, of course.
Mychaeel is offline   Reply With Quote
Old 19th Nov 2004, 03:48 AM   #5
TheSoepkip
Registered User
 
Join Date: Nov. 15th, 2004
Posts: 3
Hey Mychaeel,

Thanks for your reply, this makes things much clearer.

Quote:
Originally Posted by Mychaeel
Objects of classes not derived from Actor don't work with replication; all the native replication magic is in Actor. Thus, since your object cannot be replicated to the client, passing a reference to it from server to client won't do any good -- even if the client receives some sort of unique object identifier (which it probably does), there's no corresponding object on the client to point it to.
Well just for the sake of (a pointless) argument: there is a corresponding object on both server and client. I create the object on both client and server. Therefore "it should" be able to pass it ... Guess I'm asking too much.

Quote:
Originally Posted by Mychaeel
There's the point: Your object doesn't exist on both server and client. Only Actor-derived objects can do that trick.
Yeah that's the point indeed ... I don't want to use actors. Actors come with a lot of overhead which I really don't need when replicating maps, sets and other simple datastructures.

Quote:
Originally Posted by Mychaeel
If you want to pass structured information from server to client, maybe you should consider using a struct instead of an object. If your struct contains references to objects, the limitations mentioned above apply for those too, of course.
I think I will resort to do that. Back to the old event driven updates I guess.

Once again thanks for the insights M. If I sound a bit grudgy please don't take it personally... this has been very helpful. I'm just a bit fed up with not making that much progress at the moment. I feel that replication should have either used event driven netupdates or fully transparent RPC ... it all feels a bit like it's stuck somewhere in between .

Anyway .... back to the design table .

Thanks !

Last edited by TheSoepkip; 19th Nov 2004 at 05:29 AM.
TheSoepkip is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 04:52 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.

Copyright ©1998 - 2012, BeyondUnreal, Inc.
Privacy Policy | Terms of Use
Bandwidth provided by AtomicGamer