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 ericelbracista · Aug 23, 2020 at 09:22 PM · variablesmethods

Method variables change value all at once (2020.1.2f1)

Hi, so I have a grid composed by nodes, each of these nodes has a script with a method used to calculate the grid coordinates of a neighbor, the problem is that both of the out variables return the same value, the last one that was set to one of them. Here's the code:

 //These are the node cords in the grid, I've checked these and they're fine
 int x;
 int y;
 public void GetNeighborNode(int dir, out int neighborX, out int neighborY)
     {
         switch (dir)
         {
             case 1:
                 neighborX = x + 1;
                 neighborY = y + 1;
                 break;
             case 2:
                 neighborX = x;
                 neighborY = y + 1;
                 break;
             case 3:
                 neighborX = x - 1;
                 neighborY = y + 1;
                 break;
             case 4:
                 neighborX = x + 1;
                 neighborY = y;
                 break;
             case 6:
                 neighborX = x - 1;
                 neighborY = y;
                 break;
             case 7:
                 neighborX = x + 1;
                 neighborY = y - 1;
                 break;
             case 8:
                 neighborX = x;
                 neighborY = y - 1;
                 break;
             case 9:
                 neighborX = x - 1;
                 neighborY = y - 1;
                 break;
             default:
                 neighborX = -1;
                 neighborY = -1;
                 break;
         }


Could this be a bug or am I missing something?

Comment
Add comment · Show 5
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 highpockets · Aug 23, 2020 at 09:36 PM 1
Share

Seeing the script that is calling this would be helpful. It is possible that both outs return the same value in every single case depending on what you are passing the function. Also, x and y are never given values so they always equate to 0 as an int cannot be null, so I assume that might be your issue

avatar image ericelbracista highpockets · Aug 23, 2020 at 09:49 PM 0
Share

Hey there, as I said in the comment, the x and y variables have the correct value, they're set by another script, here you have the line of the script calling the function: obj.GetComponent<Node>().GetNeighborNode(dir * 2, out NextNodeX, out NextNodeX); (There aren't any more lines interacting with the script), and the variables in the calling script aren't neither the problem since I've done some debugging in the node script and the values were sent and saved correctly, the problem, is that the both of the variables return the same value, although they were set different ones.

avatar image highpockets ericelbracista · Aug 23, 2020 at 10:11 PM 1
Share

Ok, the x and y variables are private in the script you have provided, so I don’t know how you are changing them from another script unless you modified this script before posting it. Also, where are you setting the dir value before you pass it to the function? And I just noticed that you are passing NextNodeX, NextNodeX.. I think one might need to be NextNodeY

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by ericelbracista · Aug 23, 2020 at 10:11 PM

After some researching, it seems that it was caused due to that I was receiving the two values in the same variable. Although the debugging I made was done in the script calculating the cords, so I can't understand how, but fixing the reception error fixed the calculation error.

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

133 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 avatar image avatar image avatar image avatar image

Related Questions

Does a reference to a script have up-to-date info ? 1 Answer

cant change variable from a method? timer stays at 0! 1 Answer

How to go to a function using a variable? 1 Answer

Variable Not Changing In Method 1 Answer

Calling a variable based on a variables name? 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