initializate player with out Network.Instantiate??

Srry… it’s me asking again hehe. I can’t seem to find an answer to this in the manual.

If i have a “player” build in a prevuis level, make it persistent, but when it comes to start the network how do i do with out the Network.Instantiate function?

I know i need to asign it a network group… what else?

you can use networkView.RPC to instantiate objects on connected players.

Most important is the NetworkViewID … I think there is an example somewhere in the docs. Either for RPC, or NetworkViewID. I’m here just with my iPad so it’s not easy to look up for me. But you should find it if you look in the docs in the various networking sections and scripting reference :wink:

Been traying a full day to work this out. RPC’s calls are driving me crazy.

My problem is that i have cars build up from diferent parts. Basically i trow the parts into the scene and once set child of the car i set it’s local position relative to the car.

For local testing porpuses (simulating SQL)i have a Sort of DataBase holding all available parts and i save all the player’s car data to player prefs.

now, every time i load the car it apears with the color and parts the player build it.

Then it comes the hard part. Network. The mode is a race lobby, the host select a track the level is loaded, and each player’s car is loaded from players prefs and spawned into a pits slot. The problem is that using network instantiate the only thing that gets “registered” on the net is the base car prefab.
(local player see his car with the parts, and see the remotes as the base car prefab only)

Ok, this is because the base car prefab once spawned it checks for any parts on the players prefs. If a part is found it is spawned.

So as you see parts are spawned localy.

I can’t spawn every part and have it networked on it own that would consume a lot of bandwith. Plus each spawned part will be child of the local player no matter who’s part are they.

Aparently instantiation works directly with prefabs. So i was wondering… How can i save a player made prefab on the fly?? so then i can network instantiate that prefab? would other players “see” that prefab even if wasn’t saved on his client?

Please i really need some help on this, im running out of time :frowning:

Ok… im getting close. I have an issue thou. How can i get the network player istance across the network to add to the names?

the NetworkPlayer.ToString(); say i need an istance of type networkPlayer ??

i want to assign names like name += networkPlayer.index???

anyone? :frowning:

sorry i have to bump this again…

Can someone give me a guide on how to initializate a gameobject and it’s childs with out the need of network.instantiate or a pre-made prefab?

Please?

in Leepo’s example 4 you can find out how to have the names of the players available on all clients.
And if you can’t/don’t use network.instantiate there is only one alternative and thats RPC.

Leepo’s examples :
http://forum.unity3d.com/viewtopic.php?t=30788

i’ve been trough that tutorial allready and it uses network.instantiate. I know how to use RPC but i’d like to know what needs to be sent and in wich way in order to initializte the gameobject across the network.

Well, I’d say that’s highly dependent on your individual setup. From your previous message it seems as if you have a rather complex set up for your objects. What I’d usually do in such a case if have some manager on each client which handles the RPC communications. Then you just send “create object for me, plz, kkthx?” and the manager handles all your complex stuff.

You’d also usually have that manager handle all your players. If you have an authoritative server, that server could be the “master” and then send all the players to the clients (e.g. on request, when they login, or whenever a player is logging in and joining the game). Then each client knows all players all the time and when the client also knows which game objects belongs to which players (which can be done either through linking them to the NetworkViewIDs or via your own player-id lookup tables which you’d usually implement with Hashtables), the clients can display everything correctly.

It’s admittedly not quite easy to grasp at first. I remember when I first started implementing multiplayer into my game, I had to stop working on my project for about a week and felt “there’s no way I’m gonna get this done”. After about a week my mind got used to it and now it’s easy :wink:

It’s certainly wise to start this with very little steps … otherwise you’re just up for frustration. If you feel you can’t handle it - make your steps smaller or give your self some time.

Hi jashan, thx for replying.

Yes i do feel like you say hehe. This proyect’s networking is way over my head at this point. But it is a proyect i can’t walk away from and nither have much time to get this issue solved.

I’ve try to implement a session info on the server to know who and what does every one have but in the end i keep runing with the same problem.

Offline, when the base car spawns (base body and frame) it checks the player data base (SQL in the future) for parts on that car. If a part is found it is instantiated and automatically parent to the main body. To the naked eye this happen practically at the same time.

Using Network.Instantiate instead i have to asign the parts parent depending on who is the owner…

With two players is easy since the part just would ask if networkView.isMine then my parent is tagged “localPlayer” else if the nView is not mine then my parent is the other guy.

Now when i have more than 2 players im stuck. Because the part just ask the same as above but at the end it will say something “Ok, if this nView isn’t mine then who the ***** is my parent??” and the parts just stays at position 0,0,0 :frowning:

I don’t have an idea on how to link the network instantiated parts to their respective parent when there are more than 2 players.

That’s why i think that if i can instantiate locally before connecting and make the player’s car persistent until race is loaded then i do the network initialization on the player’s car wich is allready builded. That way i woun’t have any issue parenting things arround.

But i really can’t find any reference on that.
I can’t sync every single part either that would be network bandwith killer plus parts gonna kinda lag off the cars…

The fact that parts are automatic instantiated after the car is get’s parenting difficult when more than 2 players.

I’m inside a cloud…

I also thought of making the parts render on/off instead but that will end on a very very heavy prefab because it would have to have all posible parts inside it

:?

Sorry to hear that …

So you’ll likely have to synchronize those databases across all clients and make sure that they’re capable of handling multiple players simultaneously (at least all players currently in a game). Then just send via RPC the signal “instantiate” and let each client handle all the customized stuff themselves. I wouldn’t recommend creating network views for each detail in there - just one parent-object which controls all the stuff below.

Unless you have just a 2 player game, I wouldn’t even test with only two players because it’s a very special case that doesn’t show much about what’s really going to happen.

I’d say that’s because basically you’re doing a hack which assumes you only have two players. And as you’ve noticed: That won’t work in actual multiplayer (instead of dualplayer).

One approach: Each player has a unique ID. Obviously, those IDs must be really unique. That’s usually something that you’ll let the server handle (which you hopefully have because otherwise it’ll be pretty difficult). Server knows everything about all players (i.e. your “databases” must be available on the server, i.e. your clients need to send all the data from their local databases to the server so the server can manage them).

Server updates all clients with all the data, using the unique IDs. Then, when you send the RPCs for instantiation, you not only send the NetworkViewID so that it can be properly assigned but also the player ID so that you can connect the two.

Sounds too complicated for me, to be honest.

Plus I don’t think it would really make any sense.

Again, sounds like making things more complicated than necessary to me.

What you need is a clear design regarding who’s responsible for what. That’s the only way you’re gonna come up with a proper solution.

I think i’m getting close here.

see if you can follow me :

each part prefab has a script atached that manage the parenting and localPosition.
if i make a query using networkView.owner it returns the networkplayer index of the player to who that part belongs.

On the car side i could do something like

OnNetworkInstantiated name += networkView.owner

Then the part could do a query like

if car.networkView.owner == myOwner
then myParent = “car” +myOwner

or something like that? is there a unity function that stores all network objects inside an array so i could use a for loop?

On the other hand having the server handle the data base is somthing i try but then how i send Transform types if RPC only allow float,int,String, nView,NetworkPlayer, Vector3 and Quaternion? :?

What would you need to send Transform types around for? I’d highly recommend keeping your data a bit more abstract :wink:

nvmnd got it working! it was that easy after all hehe.

var Owner : NetworkPlayer;

function OnNetworkInstantiate (msg : NetworkMessageInfo) {

Owner = networkView.owner;

Debug.Log ("OWNER: " +Owner);

if (!networkView.isMine) enabled = false;

transform.parent = GameObject.Find ("PlayerBody"+Owner).transform;

 
transform.localPosition = transform.parent.GetComponent (C1bodyPartsPositions).Fbumper;
transform.localRotation = Quaternion.identity;


}

and the car on the network instantiate function just added

name+= networkView.owner;

Thx jashan for keeping up with me. i was desesperated lol.

just try with 4 games instances and it works like a charm!