Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 AntsAare · Jun 16, 2021 at 07:29 PM · bug-perhapsenumfor-loop

Value of Enum changes randomly

This is my Code, I've talked with many people and noone knows what's going on I'm looping through an array of robot parts and when I debug.Log inside the loop everything is fine, there is one left arm and one right arm. But when I loop through it outside of the for-loop it shows two right arms, with literally no code inbetween. It always changes from Leftarm to rightarm, never any other part.

 private RobotPartData[] TrySelectPartsFromWallet(RobotDefinitionData robotDefinitionData)
         {
             List<RobotPartData> robotPartDatas = new List<RobotPartData>();
 
             foreach (var equippableData in robotDefinitionData.equippableDatas)
             {
                 RobotPartData robotPartData = WalletCatalogue.Instance.GetRobotPart(equippableData.nftID);
                 
                 robotPartData.SetEquipSlot(equippableData.equipSlot);
 
                 robotPartDatas.Add(robotPartData);
                 Debug.LogError($"{robotPartData.equipSlot}");
             }
 
             foreach (var robotPartData in robotPartDatas)
             {
                 Debug.LogError($"{robotPartData.equipSlot}");
             }
             return robotPartDatas.ToArray();
         }

I'm not even sure if this is unity specific or a c# compiler bug. The equipslot variable is just an Enum, and isn't getting accessed inbetween, everything is running synchronouslyalt text

image.png (39.2 kB)
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
2

Answer by unity_ek98vnTRplGj8Q · Jun 16, 2021 at 10:40 PM

It looks like when you call WalletCatalogue.Instance.GetRobotPart(equippableData.nftID); it is returning the same object for both the Left Arm Equippable Data and the Right Arm Equippable Data. When you loop through it the first time it grabs the left arm object and tells it that it is a left arm object, then logs it. Then when you ask for the Right Arm robot part with the GetRobotPart() it gives you the same object that you just said was a Left Arm robot part, so it overwrites equipSlot with Right Arm then adds it to the list again. Now you have the same object in the list twice in a row, and that object has most recently been given an equip slot value of Right Arm.


To fix you need to make sure that your call to GetRobotPart is actually returning 2 distinct objects when you give it the left and right arm nftID values.

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

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

122 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

Related Questions

How to set a value for each level without using a switch statement 2 Answers

javascripts and Enum ( for loops get name) 1 Answer

[Bug?] int parameter on dynamically added onClick-Event is wrong 1 Answer

for in loop in Unity iPhone? 2 Answers

For loop on collision (two hit kill) 2 Answers


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