Author Topic: Game "crash"  (Read 5165 times)

matis

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 18
    • View Profile
Game "crash"
« on: February 07, 2013, 03:36:53 AM »
Hi,
I just finished changes in my codes to to be able use .Create and also parent objects in correct objects.
Code for .Create:
  1. public static int terrain_i;
  2. public static int vegetation_i;
  3.        
  4. public static GameObject[] ter_position;
  5. public static GameObject[] veg_position;
  6.  
  7. void Start (){
  8. ter_position = GameObject.FindGameObjectsWithTag("ter_position");
  9. for (var i =0; i < ter_position.Length; i ++){                 
  10. terrain_i = i;
  11. TNManager.Create (terrains [Random.Range (0, terrains.Length)], ter_position[i].transform.position, ter_position[i].transform.rotation);
  12. }
  13.  
  14. veg_position = GameObject.FindGameObjectsWithTag("position");
  15. for (var i = 0; i < veg_position.Length; i++) {
  16. vegetation_i = i;      
  17. TNManager.Create (vegetation [Random.Range (0, vegetation.Length)], veg_position[i].transform.position, veg_position[i].transform.rotation);   
  18. }
  19.         }

and code for parenting:
  1. void Awake () {
  2.         transform.parent = cube_gen.ter_position[cube_gen.terrain_i].transform.parent;
  3.         transform.localScale = new Vector3 (0.0078f, 0.0078f, 0.0078f);
  4.         }

Both scripts works great when Iam using scene without menu that mean when I just hit play scene in editor - objects are created and moved as a childs to corrects objects and they are resized.

Problem is when Iam using this with start server, join,... For test Iam using your example main menu scene, I was added my scene to Example Menu script in inspector also I added all object that are .Created to TNManager. When I start server(local host for me) and chose my scene from selection, my scene is loaded I see it for about 1second and then is scene switched to Main Menu where I can connect to IP or stop server. After this I have just one error: NullReferenceException: Object reference not set to an instance of an object
terrain_set.Awake () (at Assets/Scripts/World/Basic/terrain_set.cs:7)

which is reference to this line:
  1. transform.parent = cube_gen.ter_position[cube_gen.terrain_i].transform.parent;

I dont really know what is wrong with that or why my scene drop to main menu every time. I have this problem also when I use if(!TNManager.isHosting)return; in my .Create script. When Iam not using my .Create script - Iam deactivate that script - so no terrain and vegetation is created I dont have this problem I can walking around in game with no problem.

I hope you understand me. Thank you for your time.

PS.: How to make players? I know I probably need to .Create player prefab when player is joined to game but which script must be on player object, how to synchronize move or how to set owner of this object to be able move with.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Game "crash"
« Reply #1 on: February 07, 2013, 09:52:18 AM »
If it's giving you a null exception, then one of the objects you are trying to use is null.
  1. cube_gen.ter_position[cube_gen.terrain_i].transform.parent;
Check cube_gen != null and cube_gen.ter_position != null.

matis

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 18
    • View Profile
Re: Game "crash"
« Reply #2 on: February 07, 2013, 10:26:06 AM »
with this code:
  1. void Awake () {        
  2.                 if (cube_gen.ter_position[cube_gen.terrain_i] != null){
  3.                 print ("ter_position isnt null");
  4.                 }
  5.         transform.parent = cube_gen.ter_position[cube_gen.terrain_i].transform.parent;
  6.         transform.localScale = new Vector3 (0.0078f, 0.0078f, 0.0078f);
  7.         }

is "ter_position isnt null" printed to console and game is switched to main menu
I hope != means isnt:)

matis

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 18
    • View Profile
Re: Game "crash"
« Reply #3 on: February 09, 2013, 09:30:05 AM »
Hi,
another thing what I noticed is when Iam using just my .Create code without
  1. transform.parent = cube_gen.ter_position[cube_gen.terrain_i].transform.parent;
  2. transform.localScale = new Vector3 (0.0078f, 0.0078f, 0.0078f);
  3.  
on created object (so created objects are not childs of objects and they are not resizes) game is still switching to main menu. Really dont know why:(

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Game "crash"
« Reply #4 on: February 09, 2013, 06:48:47 PM »
If the game goes back to the main menu without you doing it, then either you've actually told TNet to load the menu after starting the game at some point (and you have the channel set to save everything), or you're actually getting disconnected due to your version of the server not matching the client's. When in doubt, delete "server.dat", and add a bunch of Debug.Log statements -- for example before a LoadLevel call to figure out where it's called from.

matis

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 18
    • View Profile
Re: Game "crash"
« Reply #5 on: February 09, 2013, 07:06:45 PM »
EDIT: ok so I was deleted for now your void OnNetworkLeaveChannel () from ExampleMenu script and game dont drop to menu any more - I will make my own main menu with start and joint to server tomorrow I think it will be good
« Last Edit: February 09, 2013, 07:31:05 PM by matis »