Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 ODINKONG · Apr 13, 2017 at 12:09 AM · androidunity5bug reportstringscorrupted

Mass instantiate causes corrupted strings on slower machines.

I'm instantiating about 6 playing cards with information on them. I know you are not supposed to instantiate a ton of thing at once and I plan on separating the instantiates with animations, however I noticed that when the game is run on a phone the strings show up corrupted. Armor for example will say something like Armr. This does not happen on my much faster PC. Only on Android does the bug appear. Is this a bug with unity?? It sure seems like it to me. I am not doing anything special with these strings I'm just setting them = to the text holder on the card.

I agree this really does make no sense

here is the script for opening the card the filed that comes out wrong is Card.type.text

 public UICard OpenUnitCard(BoardManager.compressedUnit u){
     GameObject g =    Instantiate (largeCard) as GameObject;
     g.transform.SetParent (packOpeningCanvas.transform);
     Image backImage = g.GetComponent<Image> ();
     RectTransform recTran = g.GetComponent<RectTransform> ();
     g.transform.localScale = new Vector3 (1.1f, 1.1f, 1.1f);
     recTran.anchoredPosition= new Vector2 (.5f, .5f);
     recTran.rect.Set (0.5f, 0.5f, recTran.rect.width, recTran.rect.height);
     BoardManager.compressedUnit stats = u;
     UICard card = g.GetComponent<UICard> ();
     if (u.unitClass == 1) {
         backImage.color = new Color (1f, .7f, .7f, 1); // light red
     }
     if (u.unitClass == 2) {
         backImage.color = new Color (1f, .9f, .7f, 1);  // light yellow
     }
     if (u.unitClass == 3) {
         backImage.color = new Color (.6f, .6f, 1, 1); // light blue
     }
     if (u.unitClass == 4) {
         backImage.color = new Color (.7f, 1, .7f, 1); // light green
     }
     if (u.unitClass == 5) {
         backImage.color = new Color (.85f, .6f, 1, 1); // light purple pink
     }
     card.des.text = stats.description;
     card.Type.text = stats.type;
     card.character.sprite = UnitIDMaker.instance.GetUnitTypeByID(u.ID).GetComponentInChildren<SpriteRenderer>().sprite;  // this is to show you the unit
     card.health.text = System.Math.Round(stats.maxHealth,1).ToString ();
     card.accuracy.text = System.Math.Round(stats.accuracy,1).ToString ();
     card.attackSpeed.text = System.Math.Round(1/stats.atkSpeed,1).ToString (); // convert to attacks per second
     if (stats.dmg > 0) {
         card.attack.text = "M" + System.Math.Round (stats.dmg, 1).ToString ();

     }
     if (stats.rangDmg > 0) {
         card.attack.text = "R" + System.Math.Round (stats.rangDmg, 1).ToString ();
     }
     card.critChance.text = System.Math.Round(stats.critChance,1).ToString ();
     card.defense.text = System.Math.Round(stats.defense,1).ToString ();
     if(stats.isMelee){
         card.critDamage.text = System.Math.Round(stats.fullMeleeCrit,1).ToString ();
     }
     else{
         card.critDamage.text = System.Math.Round(stats.fullRangedCrit,1).ToString ();
     }
     if (stats.eqSpotTypes.Count > 0) {
         card.EqIcon1.sprite = getEquipmentTypeImage (stats.eqSpotTypes [0]);
         card.EqIcon1.gameObject.SetActive (true);
         if (stats.eqSpotTypes.Count > 1) {
             card.EqIcon2.sprite = getEquipmentTypeImage (stats.eqSpotTypes [1]);
             card.EqIcon2.gameObject.SetActive (true);
             if (stats.eqSpotTypes.Count > 2) {
                 card.EqIcon3.sprite = getEquipmentTypeImage (stats.eqSpotTypes [2]);
                 card.EqIcon3.gameObject.SetActive (true);
                 if (stats.eqSpotTypes.Count > 4) {
                     card.EqIcon4.sprite = getEquipmentTypeImage (stats.eqSpotTypes [3]);
                     card.EqIcon4.gameObject.SetActive (true);
                 } else {
                     card.EqIcon4.gameObject.SetActive (false);
                 }
             } else {
                 card.EqIcon3.gameObject.SetActive (false);
                 card.EqIcon4.gameObject.SetActive (false);
             }
         } else {
             card.EqIcon2.gameObject.SetActive (false);
             card.EqIcon3.gameObject.SetActive (false);
             card.EqIcon4.gameObject.SetActive (false);
         }
     } else {
         card.EqIcon1.gameObject.SetActive (false);
         card.EqIcon2.gameObject.SetActive (false);
         card.EqIcon3.gameObject.SetActive (false);
         card.EqIcon4.gameObject.SetActive (false);
     }
     return card;
 }

This code never causes any issues except when its used in this function at the begging of the game

 public void openStartPack(){
     open1Unit (1); // common
     open1Unit (1); // common
     open1Unit(1); // common
     open1Unit (1,2); // ucommon
     open1Unit (1,2); // uncommon
     open1Unit (1,2); // uncommon
     open1Unit (1,3,3); // uncommon
     open1Unit (1,3,4); // uncommon
     open1Unit (1,3); // Rare
     openAnEquipment(1);
     openAnEquipment (1);
     openAnEquipment (1);
     GameManager.instance.gold += 100;
     GameManager.instance.currentCampaignMission = 1;
 }

Every Time i call open1unit a unit is spawned. This unit rolls stats which does not include assigning the string that we are getting corrupted. That string is set by default in the prefab in the inspector for the unit or item, and it is never changed IE a knight prefab will always have a type of knight. After it does that it calls the card opening function passes its stats on and destroys its self.

Like I said this is the only time it causes an issue and after the unit is received opening its card later will show the correct string even it was initially corrupted this means it is only displaying incorrectly in the text element but not saving incorrectly. It also only happens on the android.

Comment
Add comment · Show 7
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 ritoban · Apr 13, 2017 at 03:02 AM 0
Share

So the cards have UI.Text Components, right? Are you sure that its not a typo anywhere?

avatar image ODINKONG · Apr 13, 2017 at 03:18 AM 0
Share

Yes exactly they are UI text components and I and setting the string after instantiating them. I know it's not a typo because it's only happening on Android. It works perfectly on PC.

avatar image ritoban · Apr 13, 2017 at 04:24 AM 0
Share

Can you post the code you're using for instantiating the objects as well as the resulting text object? This really makes no sense.

avatar image ODINKONG · Apr 13, 2017 at 06:48 AM 0
Share

It really doesn't make sense your right. I'm not so concerned with my game being buggy as much as unity possibly having a bug because i can easily fix this with a work around. I would however prefer to know why it is happening before I do. Anyway I edited the question to include the code. Thanks for taking a look ritoban.

avatar image Kossuranta · Apr 13, 2017 at 11:47 AM 0
Share

Sounds like a bug to me where the operation takes too long, but the result of something like Armor co$$anonymous$$g as Armr sounds really strange to me.

It should work like you have done it, but have you tried pooling which would be much better approach anyway? You could Instantiate stack of cards and GetComponents for them at the start of the game and then just edit them when showing. Having Instantiate and four GetComponents with multiple cards might be somewhat heavy process.

Show more comments

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

129 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 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 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 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 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 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

Remove already published achievements - Google Play Store 2 Answers

Failure [INSTALL_FAILED_CPU_ABI_INCOMPATIBLE] (solved) 1 Answer

Why does my pause & quit menus appear when I load next level? 0 Answers

I am not able to get the currentActivity,and i am getting the following error 0 Answers

why unity IPA file size increased after installation as compare to unity APK? 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