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 d112570 · May 27, 2014 at 06:10 PM · update

How do you update code/stage/screen at runtime?

How would you go about updating the stage at runtime?

For example I was replacing green grids for a different color and they stayed green even thou the code was correct, so I found a workaround where I tell the code to wait 0 Seconds then it worked.

I have the problem again, I destroyed my grid, then recreated my new grid and all my buildings are missing from the grid that was destroyed. I have a grid, had the grid replaced with another grid,

 EditTheGrid();  // Here I replace some of the green grids with a different color.

I need something here to update the code/Stage/windows whatever its called.

 PlaceBuildings(thePath,loc0,loc1,loc2,loc3); // Here I add the buildings

All the green grids have buildings and non green grids have missing buildings. When I use the print command, the buildings are listed in my list. It just wasn't updated on screen. I am unable to use the wait 0 second routine this time around

 if (vBuildTemp == 1) StartCoroutine(MyMethod());
 
 IEnumerator MyMethod() { // Wasn't updating grids, so I added this
         yield return new WaitForSeconds(0);
         vBuildTemp = 0;
         viewBuildings = true;
     }

I had the same problems using the Language Director's Lingo and they had a command "UpdateStage" there should be something similar in unity.

For easier understanding if you destroy a game object folder then recreate the game folder it seems like all the objects you created goes into the previous deleted game folder it works if I use the wait for seconds then it created the object in the new folder. Maybe a bug in Unity?

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by tanoshimi · May 27, 2014 at 06:29 PM

Any runtime changes should take effect immediately - no "UpdateStage" method is necessary, and I've never heard of a workaround involving waiting 0 seconds. "Folders" are not related to runtime - they're how your project is stored on disk. If you post the actual code that doesn't work we can probably point out the true issue.

Comment
Add comment · Show 2 · Share
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 d112570 · May 28, 2014 at 10:46 AM 0
Share

Unable to paste all the codes, too large.

 EditTheGrid();

// Here i place the grid, and if the grid is not green delete the grid and replace with a different color, buildings with a different grid color are missing, the grids are there

 PlaceBuildings(thePath,loc0,loc1,loc2,loc3);

// Here I place the buildings.

 public static void PlaceBuildings(GameObject thePath,int loc0,int loc1,int loc2,int loc3) {
         string objectType = thePath.transform.parent.gameObject.GetComponent<Info>().sizeFeature.ToString();
     int grid$$anonymous$$ax = 1; int rota = 0;
     if (objectType == "Giant")         grid$$anonymous$$ax = 27;
     if (objectType == "Planet")        grid$$anonymous$$ax = 19;
     if (objectType == "SmallPlanet")grid$$anonymous$$ax = 13;
     if (objectType == "Dwarf")         grid$$anonymous$$ax = 07;
     if (objectType == "Satellite")     grid$$anonymous$$ax = 04;
     if (objectType == "Asteroid")     grid$$anonymous$$ax = 01;

     for (int grid = 0; grid <= grid$$anonymous$$ax; grid++) {
         for (int area = 0; area <= 6; area++) {
             if ($$anonymous$$yScript.gridLocation[loc0,loc1,loc2,loc3,grid,area] != 0) {
                 int i = 1;
                 while(i <= 8) {if (gridLocation[loc0,loc1,loc2,loc3,grid,area] == i) buildingPrefab = Resources.Load("Station" + i, typeof(Transform)) as Transform; i++;}
                 List<int> rotaList = new List<int>(new int [] {90,150,210,270,330,30,90}); i = 0;
                 foreach(int item in rotaList) {if (area == i) rota = item; i++;}
                 Transform newBuilding = (Transform) Instantiate(buildingPrefab, new Vector3(0, 0, 0), Quaternion.identity);
                 newBuilding.transform.parent = GameObject.Find("$$anonymous$$ain Camera/Build$$anonymous$$ode/Grid/" + grid + "/" + area).transform;
                 newBuilding.transform.name = gridLocation[loc0,loc1,loc2,loc3,grid,area].ToString();
                 foreach (Transform child in newBuilding.transform)
                 {
                     child.gameObject.layer = 0;
                     if (child.gameObject.collider) child.gameObject.collider.enabled = false;
                     foreach (Transform grandChild in child){
                         grandChild.gameObject.layer = 0;
                         if (grandChild.gameObject.collider) grandChild.gameObject.collider.enabled = false;
                     }}
                 newBuilding.transform.localPosition = new Vector3(0,0,0);
                 newBuilding.transform.localRotation = Quaternion.Euler(new Vector3(0,rota,0));
                 newBuilding.transform.localScale    = new Vector3(0.60f, 0.60f, 0.60f);
             }}}}



Here is an example replacing the grid. If I had something like updateStage then this code would work

 // Blue Aqua Farm
         count = gridColor0 + gridColor1;
         for (int p = 0 + count; p <= -1+gridColor2 + count; p++){
             Transform newGrid = (Transform) Instantiate(gridBlue, new Vector3(0, 0, 0), Quaternion.identity);
             var oldObj = GameObject.Find("$$anonymous$$ain Camera/Build$$anonymous$$ode/Grid/" + p);
             newGrid.transform.parent   = oldObj.transform.parent;
             newGrid.transform.rotation = oldObj.transform.rotation;
             newGrid.transform.position = oldObj.transform.position;
             GameObject.Destroy(oldObj); 
             newGrid.transform.name = p.ToString();
         }
avatar image d112570 · May 28, 2014 at 01:12 PM 0
Share

I changed the top script to this. Ins$$anonymous$$d of deleting and recreating I just changed the color of the object. Currently I deleted game object folder then I recreated a new game object folder, then I added the building inside the script, but only it created the building inside the deleted game object folder. This is not an answer just a work around, like the other script I had to use a wait timer for a work around.

 List<string> gridList = new List<string>(new string [] {"0","1","2","3","4","5","6","Border","Background"});

 // Blue Aqua Farm
         count = gridColor0 + gridColor1;
         for (int p = 0 + count; p <= -1+gridColor2 + count; p++){
             foreach(string item in gridList) {
                 var obj = GameObject.Find("$$anonymous$$ain Camera/Build$$anonymous$$ode/Grid/" + p + "/" + item);
                 if (item != "Background") obj.renderer.material.color = new Color32(0,0,255,255);
                 if (item != "Background") obj.renderer.material.SetColor("_Emission", new Color32(0,0,255,255));
                 if (item == "Background") obj.renderer.material.color = new Color32(0,0,50,150);
             }}

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

22 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity is not updating my scripts 2 Answers

Expecting ( found Update (Javascript) 1 Answer

Code isn't Recursive in update? 2 Answers

Coroutine - events not working 2 Answers

How to detect empty slot and spawn gameobject there? 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