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 uberokeer · Jul 02, 2013 at 06:32 PM · stringintvalues

Set variable and then keep it that way

Hello, what I'm trying to do is set a variable from another variable and then when the variable the other variable is set to changes the first variable doesn't. That sounds to complicated here's a simpler version.

Let's say i have 2 int variables the first one and the second one is:

 var int1 : int;
 var int2 : int;

now i have a string variable.

 var stringname : string;

but stringname is named after the 2 int variables and is formatted like this: "`stringname[int1 value, int2 value]`" but after stringname is named, i then want to keep it named that way even after int1 & int2 values are changed. I know it sounds complicate, sorry :/ i just can't figure this out for the life of me. Thanks in advance. ;D

Comment
Add comment · Show 1
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 robertbu · Jul 02, 2013 at 06:47 PM 1
Share

You are going to have to provide more source and perhaps an example. Some variables refer to data by reference, some refer to the data by value (actually contain the data). Everything you list above refers to the data by value (or in the case of strings an immutable reference). So the behavior should be what you want. So we need a bit of source that shows the behavior that you don't want to understand the problem you are trying to solve.

1 Reply

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

Answer by Yokimato · Jul 02, 2013 at 07:09 PM

If I understand your question:

Raw data types (i.e non-objects) work as you intend.

 var x : int;
 var y : int;
 
 var z : string;
 
 x = 1;
 y = 2;
 z = "stuff" + x + y; // stuff12
 
 x = 100; //x changes but z remains stuff12
 
 

However, objects behave differently since you're really dealing with a pointer to the object and thus you just assign the pointer (i.e you know have 2 pointers to the same object)

 var x : GameObject;
 var y : GameObject;
 
 x = GameObject.Find(...);
 z = x; // both z and x point to the same object
        // and thus any changes to x apply to z and vice versa

If you didn't want this functionality, you would need to make a copy of the object (creating a new instance). This way, you end up with x pointing to the original object and z points to its own, copied object.

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

16 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

Related Questions

parseInt givin' me issues! 2 Answers

How to convert a string to int array in Unity C# 1 Answer

How to turn a String to an Int? 5 Answers

Convert int to string and back again 2 Answers

js "Cannot convert 'String' to 'int'." error 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