Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Yinoguns · Aug 18, 2014 at 09:32 PM · buildmapcreationinconsistent

Two In-game modes, one doesnt spawn all Rooms

Starting Background Info

Hello, firstly I want to say that my project here is not small or "simple" it was my Dissertation for my University Degree.

The skinny of it is there are two modes, editing and playing.

  • The Former has you alter the instance and rotation of the rooms that make a grid based map.

  • The Latter is to play this map, all the perimeter rooms create adjacent rooms to spawn NPC Zombies that come to eat you, "nom nom nom".

Image Example

Below is an image of the game, separate rooms with their own Navigation Graphs that auto-link with one-another to create one complete graph.

alt text

The Working

As mentioned before, I have a mode for editing these rooms so you can swap a room from ie a pillar to a hall-way wall design; Now in that mode all works fine and the rooms are all created.

The Not-Working

However for some reason in the Play Mode, which is the same scene but with slightly different path through the same script

When running in the Unity-Editor, the game works fine however in a build PC and Mobile-Android tested, only the first 2 rooms are created.

Problem Idea

One idea I have for my problem is in PlayMode the game has a some more to do, that is the created rooms have to load and built their navigation graph. However this mode creates only 2/70 rooms while edit mode manages to instantiate all 70.

One thought I have is to create a Coroutine system to do this process overtime, just like an Asynchronous Task in Java Android development, but I am unsure if that would help at all considering the above mention of 2/70 vs 70.

Code for your consideration

MapModeManager.Start

 void Start () {
 
         editMode = SaveMemory.isEditMode();//get Mode
         Debug.Log("Edit Mode: "+editMode);
         //Get SaveMemory to find Dims of save file
         roomsX = SaveMemory.getDim(0); roomsZ = SaveMemory.getDim(1);//get Dimensions
 
 
         MyDebug.log("Edit Mode: "+editMode);
         if( editMode ){
 
             if( DesktopApplication ){
                 Instantiate( EditorPlayer,             spawnPlayerPos.transform.position, Quaternion.identity);
             }else
             {
                 Instantiate( EditorPlayerMobile,     spawnPlayerPos.transform.position, Quaternion.identity);
             }
         }else{
             if( DesktopApplication ){
                 Instantiate( CombatPlayer,             spawnPlayerPos.transform.position, Quaternion.identity);
             }else
             {
                 Instantiate( CombatPlayerMobile,     spawnPlayerPos.transform.position, Quaternion.identity);
             }
         }//editMode
         Destroy(tempCamera);
 
         
         //set Room Size
         Rooms = new GameObject[roomsX,roomsZ];
         Room roomScript;
         int roomID, roomRot;
 
         MyDebug.log("About to read from File :");
         MyDebug.log(SaveMemory.getDesiredFile(true) );
         try{
             using( StreamReader sr = new StreamReader( SaveMemory.getDesiredFile(true) ) ){
 
                 if( !SaveMemory.isNewFile() ){
                     MyDebug.log("Not new File (skipping dims)");
                     Debug.Log("Going to read file: "+SaveMemory.getDesiredFile(true) );
                     sr.ReadLine();sr.ReadLine();//skip Dimensions
                 }else{
                     MyDebug.log("New File");
                     Debug.Log("Should try to Read File");
                 }
 
                 MyDebug.log("Loop Spawn Rooms; "+roomsX+", "+roomsZ);
                 //initializes Rooms
                 for(int x=0; x<roomsX; x++){
                     for(int z=0; z<roomsZ; z++){
                         //------
                         
                         MyDebug.log("Spawning Room: "+x+", "+z);
                         Rooms[x,z] = Instantiate( startingTemplateRoom, new Vector3( (float)x*spawnRoomSize, 0f, (float)z*spawnRoomSize  ) , Quaternion.identity ) as GameObject;
                         roomScript = Rooms[x,z].GetComponent<Room>();
 
                         //if edit false
                         //get info to load room
                         //RoomGO,RoomID,RoomRot,X,Z
 
 
                         if( !SaveMemory.isNewFile() ){
                             string Temp = (sr.ReadLine()).ToString();
                             //Debug.Log("First Reading as String is :"+Temp);
                             roomID = int.Parse( Temp );
                             Temp = (sr.ReadLine()).ToString();
                             //Debug.Log("First Reading as String is :"+Temp);
                             roomRot= int.Parse( Temp );
 
                             MyDebug.log("roomScript.roomConfig(DifferentRooms["+roomID+"], ID:"+roomID+", Rot:"+roomRot+", X:"+x+", Z:"+z+");");
 
                             roomScript.roomConfig(DifferentRooms[roomID],roomID,roomRot, x, z);
 
                         }else{
                             MyDebug.log("Create Basic Room");
                             roomScript.roomConfig(DifferentRooms[0],0,0, x, z);
                         }
 
                         
                         
                         
                     }//for
                     //Debug.Log("Row :"+x);
                 }//for
             }//using
 
         }catch(IOException e){
             MyDebug.log("Couldnt Read File");
             MyDebug.log("Exception info: "+e.Data );
         }
         
         MyDebug.log("RM.Start finished");
         finishedSpawning = true;
 
         if( !SaveMemory.isEditMode() ){
             gameObject.transform.GetComponent<AI_Manager>().enabled = true;//enable AI script
             gameObject.transform.GetComponent<AI_Manager>().activate();//run startup stuff
         }
 
 
         //Debug.Log("SaveMemory.getDesiredFile: "+SaveMemory.getDesiredFile(true) );
         
         //Enable the AI manager
 
         //Rooms[0,0].GetComponent<Room>().getDirection();
         
         
     }//Start


Room.roomConfig

 public void roomConfig(GameObject startingRoom, int roomID, int rotation, int rX, int rZ){
 
         //Debug.Log("Configuring Room: "+roomX+", "+roomZ);
 
         RM = (GameObject.FindWithTag("Manager") ).GetComponent<MapModeManager>();
         if( RM == null ){
             //Debug.Log("Didnt manage to grab RM");
             Destroy(this.gameObject);
         }else{
             //Debug.Log("Grabbed RM");
         }
 
         roomX = rX; roomZ = rZ;
 
         //give starting room (used for loading)
         ChangeRoom(startingRoom, roomID);
 
         rotateRoom(rotation);//Error call 2
 
         getScripts();
 
         MyDebug.log("Finished Configuring Room: "+roomX+", "+roomZ);
         
 
     }//


Debug Output

 Edit Mode: False
 
 About to read from File :
 /storage/.../SaveFiles/ZombieHall.txt
 
 Not new File (skipping dims)
 Loop Spawn Rooms; 7, 10
 
 Spawning Room: 0, 0
 
 roomScript.roomConfig(DifferentRooms[3], ID:3, Rot:0, X:0, Z:0);
 
 Finished Configuring Room: 0, 0
 Spawning Room: 0, 1
 
 roomScript.roomConfig(DifferentRooms[3], ID:3, Rot:3, X:0, Z:1);


End of Code/Output

In the coming days, I am likely going to get round to improving the scene bootup with Coroutine, but I wish to get the advice of the community to move this work forward.

Any questions or requests for anything please ask.

ai-prep_nodes.jpg (24.5 kB)
Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image tanoshimi · Aug 18, 2014 at 09:35 PM 0
Share

UA is not the correct place for "discussion/opinion"-type questions - those are best asked on the forum ins$$anonymous$$d. If you want us to help answer the question of why your build is behaving differently than in the editor we'd need to see your output log file.

avatar image Yinoguns · Aug 18, 2014 at 09:40 PM 0
Share

Ok sorry about this not being in the right place. And I have given the Output Log, its the last Code Block.

Also you say "why your build is behaving differently than in the editor" I think your mixed up, I have a Play and Edit mode, the Edit makes all rooms, but the Play only creates 2.

These are both when "running" the game in a build PC/Android but no problems exist in the Unity Editor itself.

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

Distribute terrain in zones 3 Answers

best map creation method 0 Answers

Inconsistency between builds. 0 Answers

Building my first 3D location-based game - A question about the "play" function 0 Answers

How to make add force/Physics consistent between editor and builds? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges