Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - toreau

Pages: [1] 2
1
TNet 3 Support / Re: TNManager.Create'ed objects doesn't initialize
« on: June 14, 2014, 08:25:48 AM »
Thanks for the reply!

I changed my code to look like this:

  1. void Start () {
  2.         playerCamera = PlayerController.instance.playerCamera;
  3.         throwAwaySackResource = (GameObject)Resources.Load( "Prefabs/ThrowAwaySack" );
  4. }
  5.  
  6. public void OnDragEnd ( dfControl source, dfDragEventArgs args ) {
  7.         if ( args.Target.GetType().ToString() == "dfPanel" && args.Data is SlotPanelController ) {
  8.  
  9.                 // Create a new ThrowAwaySack
  10.                 this.Create( throwAwaySackResource, playerCamera.transform.position, Quaternion.identity, false, args );
  11.  
  12.                 // Mark as dropped
  13.                 args.State = dfDragDropState.Dropped;
  14.  
  15.         }
  16. }
  17.  
  18. static public void Create ( GameObject prefab, Vector3 pos, Quaternion rot, bool persistent, dfDragEventArgs args ) {
  19.         TNManager.CreateEx( 10, persistent, prefab, pos, rot, args );
  20. }
  21.  
  22. [RCC(10)]
  23. static GameObject OnCreate ( GameObject prefab, Vector3 pos, Quaternion rot, dfDragEventArgs args ) {
  24.         GameObject go = Instantiate( prefab, pos, rot ) as GameObject;
  25.  
  26.         // Populate the ThrowAwaySack's inventory
  27.         InventoryController throwAwaySackInventoryController = go.GetComponent<InventoryController>();
  28.         SlotPanelController slotPanelController = (SlotPanelController)args.Data;
  29.        
  30.         Slot sourceSlot = slotPanelController.slot;
  31.        
  32.         int itemsAdded = throwAwaySackInventoryController.AddItems( sourceSlot.items[0], sourceSlot.items.Count );
  33.         sourceSlot.RemoveItems( sourceSlot.items[0], itemsAdded );
  34.  
  35.         return go;
  36. }
  37.  

...but now TNet complains that "The game object was not found in the TNManager's list of objects." I tried adding the ThrowAwaySack prefab to TNManager, and while the error message went away a) I don't think that's the right colution (or is it?) and b) the ThrowAwaySack wasn't instantiated because OnCreate() is never run.

What am I doing wrong?

2
TNet 3 Support / TNManager.Create'ed objects doesn't initialize
« on: June 12, 2014, 01:59:23 PM »
Hi!

I have an inventory system where I can drag anything from the inventory and into "the open", ie. the terrain, and I want the game to create a "sack" over the network and fill it whatever I'm throwing away.

Easy enough, one would think, but the problem I'm facing is that Create() doesn't behave like Instantiate, as it doesn't really instantiate the object. Consider this code, which is run whenever I drop an item (or items) into "the open."

  1. public void OnDragEnd ( dfControl source, dfDragEventArgs args ) {
  2.         if ( args.Target.GetType().ToString() == "dfPanel" && args.Data is SlotPanelController ) {
  3.  
  4.                 // Create a new ThrowAwaySack
  5.                 TNManager.Create( "Prefabs/ThrowAwaySack", playerCamera.transform.position, Quaternion.identity, false );
  6.  
  7.                 // Populate the ThrowAwaySack's inventory
  8.                 InventoryController throwAwaySackInventoryController = throwAwaySack.GetComponent<InventoryController>();
  9.                 SlotPanelController slotPanelController = (SlotPanelController)args.Data;
  10.  
  11.                 Slot sourceSlot = slotPanelController.slot;
  12.  
  13.                 int itemsAdded = throwAwaySackInventoryController.AddItems( sourceSlot.items[0], sourceSlot.items.Count );
  14.                 sourceSlot.RemoveItems( sourceSlot.items[0], itemsAdded );
  15.  
  16.                 // Mark as dropped
  17.                 args.State = dfDragDropState.Dropped;
  18.  
  19.         }
  20. }
  21.  

Each ThrowAwaySack has an InventoryController attached to it, and with this code the sack itself gets created over the network just fine. However, its InventoryController is never initialized, ie. it never does Awake(), which is crucial for things to work.

With f.ex. PhotonNetwork, I could do a PhotonNetwork.Instantiate() and get an initialized GameObject back, but TNManager.Create() is void, so...?

Any help is appreciated!

Thanks!

3
TNet 3 Support / Re: memory usage problem
« on: May 23, 2014, 01:19:13 PM »
I agree with djray2k; it seems like you hit some kind of treshold, and it could easily be your OS doing things in the background that TNet has no control over.

Are you sure that the TNet server and the clients are using all the memory? Could it be other processes?

4
TNet 3 Support / Re: memory usage problem
« on: May 22, 2014, 02:23:14 AM »
Can you show us some code? Also, which platform is your server running on?

I also find this statement particularly interesting:

Quote
if one client disconnect ,sometimes server lost all the client,means all clents disconnect because one player leave...the more client connect,the more easiler happen.

By "disconnect", do you mean if the client just quits the application? What happens if you bind "Q" to a proper disconnect inside the application? Same behaviour?

5
I just want to add here, for future reference, that "only synchronize when a new player joins" means setting TNAutoSync's "Updates Per Second" property to zero, if I've understood the code correctly.

6
TNet 3 Support / Re: how to do performance test ?
« on: May 20, 2014, 01:30:16 AM »
Is there some way to monitor the bandwidth used pr. client? Right now I'm using nethogs on my server, and while it works it requires a standalone server.

7
How would/should one approach this? Change the server code so that it takes care of everything weather-/season-related? Or...?

This also goes for day/night cycles, of course.

8
I've got things working as I want now, but I have more complaints. :D

I currently work with the three scenes - Connect, Game and Disconnect - but I find it extremely annoying to spend 99% of my work in the Game scene, and having to load the Connect scene every time I want to play the game.

Is this really necessary, or are there ways around it?

9
That easy! :)

The solution was to disable all of the "player-related" components, and then (inside my PlayerController.cs) enable them if you are "the player":

  1.         void Start () {
  2.                 if ( tno.isMine ) {
  3.                         characterController = GetComponent<CharacterController>();
  4.                         playerCamera        = characterController.GetComponentInChildren<Camera>();
  5.  
  6.                         characterController.enabled = true;
  7.                         playerCamera.enabled = true;
  8.                 }
  9.         }
  10.  

Thanks!

10
Huh? The camera is part of the Player prefab being instantiated...?

11
TNet 3 Support / Re: Player gets spawn twice, but only occasionally
« on: May 13, 2014, 02:07:05 PM »
After I started from scratch and implemented the "three-scene-design" it seems like that has something do with it.

12
Ok. I'm fine with that requirement as long as I'm aware of it. :)

Now!

I created a brand new project while following this tutorial, and while I change some object names here and there to be a bit more "non-tutorial", AND add some FPS-stuff to everything, it still doesn't work as expected; the second player joining the game is controlling the first player joining the game.

Download the whole thing here if you want to try it out. What I do, is:

  • Build the game, run around a bit to make sure everything works as expected.
  • Play the game from inside Unity3D, run around a bit to make sure everything works as expected.
  • Switch back to the build game, while making sure I can watch the other player, move around, and I can see that my "build movements" are affecting the other player.

I can't for the love of (put in anything here) understand what I'm doing wrong?!

13
Before I redo all this, I need to ask: does TNet require your game to have more than one scene? If so, why? That's a dependency that should be documented, no?

14
TNet 3 Support / Re: Player gets spawn twice, but only occasionally
« on: May 13, 2014, 09:58:37 AM »
Quote
1. You have JoinChannel, giving it a scene to load... and yet your OnNetworkJoinChannel is on the same script. Why not put it on a different script that actually exists as a part of your "Game" scene? You also mentioned you have 2 scenes, yet I'd expect 3 -- starting scene, game scene, and disconnect scene.

I'm actually just interested in the "Game" scene at the moment; as if it's I jump right into the game. I was thinking about creating "Connect" and "Disconnected" scenes later. I assume that's OK?

So all the scripts in question are part of the "Game" scene; the "Disconnected" have no scripts, only the GUIText-thingy I mentioned.

Quote
2. TNObject ID of 0 is only valid for something that's dynamically instantiated via TNManager.Create / AutoCreate. If you have an object that's already a part of your scene, then it must have a non-zero ID.

So that's correct, then; only the Player prefab has a TNObject, and it (the Player prefab) is instantiated over the network (via TNManager.Create().) I have no other objects with a TNObject component attached to it.

Quote
3. OnNetworkJoinChannel should only be called once per join, but it gets called on all scripts present in the scene. If you have two scripts with it, both will receive it. When in doubt, check the full call stack. NGUITools.GetHierarchy would be useful here. No idea if DFGUI has something similar.

OnNetworkJoinChannel() is only in the ConnectionController script, but it still gets called twice sometimes. Keep in mind that it doesn't happen every time I press play. I've also put some debugging into the TNManager script, and the OnNetworkJoinChannel broadcast message is sent only once. :-\

15
TNet 3 Support / Player gets spawn twice, but only occasionally
« on: May 13, 2014, 09:07:00 AM »
I have another weird problem with TNet, and this time I'll be sure to flood you with information. :) It might be related to another problem I have, but I wanted to start a new thread "to make it clean."

I have a project with two scenes; Game and Disconnect. The latter is empty, only showing a GUIText "You are now disconnected", while the former has a cube (for ground), a directional light and a "Connection" object.

The "Connection" object has two components attached to it: a TNManager, with the Player prefab attached to it, and a ConnectionController script, which is pretty basic and looks like this:

  1. using UnityEngine;
  2. using TNet;
  3.  
  4. public class ConnectionController : MonoBehaviour {
  5.  
  6.         void Start () {
  7.                 TNManager.Connect( "127.0.0.1:5127" );
  8.         }
  9.  
  10.         void OnNetworkConnect ( bool success, string message ) {
  11.                 if ( success ) {
  12.                         TNManager.JoinChannel( 1, "Game" );
  13.                 }
  14.         }
  15.  
  16.         void OnNetworkJoinChannel ( bool success, string message ) {
  17.                 if ( success ) {
  18.                         TNManager.Create( "Prefabs/Player", false );
  19.                 }
  20.         }
  21.  
  22. }
  23.  

Connecting/disconnecting works just fine, and I can mention that my client (workstation) is a MacBook Pro running the latest version of OSX, the latest version of Unity3D, and have the latest version of TNet (1.9.0b).

The server is running Debian 6.0.9, and is not running on 127.0.0.1 as mentioned in the code above, but I want certain things to be a secret. :) But - as mentioned - connecting and disconnecting works just fine (or so it seems, at least.)

The Player prefab has two components attached to it; a TNObject (id = 0) and a PlayerController script, which looks like this:

  1. using UnityEngine;
  2. using TNet;
  3.  
  4. public class PlayerController : TNBehaviour {
  5.  
  6.         static public PlayerController instance;
  7.  
  8.         private CharacterController characterController;
  9.         private Camera playerCamera;
  10.  
  11.         void Awake () {
  12.                 Debug.Log ( "PlayerController.Awake()" );
  13.                 if ( TNManager.isThisMyObject ) {
  14.                         instance = this;
  15.  
  16.                         characterController = GetComponent<CharacterController>();
  17.                         playerCamera        = GetComponentInChildren<Camera>();
  18.  
  19.                         Instantiate( Resources.Load("Prefabs/UI Root") );
  20.                 }
  21.     }
  22.  
  23.  

The "UI Root" prefab has nothing attached to it, except the standard DF-GUI stuff. I know I probably should use NGUI, but I had to choose which one to spend $90 on, and I went for DF-GUI. Sorry about that. :)

Now - back to the issue at hand.

Every now and then - most of the time, it seems - when I play the game, the Player is instantiated twice, and they are assigned two different IDs. I've attached a screenshot.

Any ideas why this is happening?

UPDATE: It might be worth mentioning that when this happens, the server says that only one client is connected.

UPDATE #2: I added some debug messages in TNManager.cs, and the second Create() method is being called twice, but I'm 200% sure that Create() is being called only once from "my end" (ie. in the ConnectionController script.)

UPDATE #3: After some more debugging, I was wrong about the 200%. :D The OnNetworkJoinChannel() in my ConnectionController script is actually being called twice, but the OnNetworkConnect() is called only once when that happens. In what cirumstances can that happen?

Pages: [1] 2