Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 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 /
This question was closed Nov 19, 2014 at 07:15 PM by meat5000 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Nk.Andrei · Aug 05, 2013 at 02:11 PM · errorarrayclasswarning

WARNING : Assignment to temporary.

What does this mean and how do I get rid of it?It keeps appearing when I try to loop through a list and modify a boolean var.

 #pragma strict
 import System.Collections.Generic; 
 
 var theOpenList     : List.<Cel> =new  List.<Cel>();
 var i : int;
 
 
 function Update () 
 {
     for(i = 0 ; i < theOpenList.Count ; i++)
     {
         
         if(theOpenList.Count > 0)
         {
             theOpenList[i].startSearch = true; 
             theOpenList[i].inList = true;                      
                     Instantiate(cube,theOpenList[i].celPos,transform.rotation);
                     theOpenList[i].cubeCheck = false;

             }
      }

}

My list is filled with elements from a class named Cel......and if I loop through the list changing the boolean var it gives me this warning.

This is my Cel class

 #pragma strict
 
 class Cel extends System.ValueType
 {
     
     var h : float;
     
     var obj       : Transform;
     var enemy       : Transform;    
     var distance  : Vector3;    
     var celPos       : Vector3;    
     var color       : Color;        
     
     var cubeCheck : boolean;
     var inList : boolean;        
     var startSearch : boolean;
     
     
     
     
     function Cel (position : Vector3, object : Transform,  enemyPos : Transform, parent : Cel, hCost : float)
     {
         h = hCost;
         celPos                = position;
         obj                 = object;    
         enemy                 = enemyPos;
         
     
         if(enemy != null)
         {
             distance = obj.position - enemy.position;
             h         = distance.magnitude * 10;
         }    
     }
     
     function Start()
     {
         startSearch = false
         cubeCheck = true;
         inList = false;
     
     }
 }
 
 I dont know waht the error means....but I need help and an explanation. 
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 Dave-Carlile · Aug 05, 2013 at 02:38 PM 1
Share

Duplicate of http://answers.unity3d.com/questions/133457/bcw0006-warning-assignment-to-temporary.html.

Please close.

1 Reply

  • Sort: 
avatar image
3
Best Answer

Answer by Peter G · Aug 05, 2013 at 03:20 PM

I think that post does a good job explaining it, but I think a slightly different solution would save you a little work. Rather than call the constructor to create a new one from scratch, clone the original, change the clone, then copy it back into the array.

 if(theOpenList.Count > 0) {
      var temp = theOpenList[i];
      //copy all the values over to a temporary object.
      temp.startSearch = true; 
      temp.inList = true;
      temp.cubeCheck = false;
      //edit all the necessary values.
 
      //Reassign the copied object to the original.
      theOpenList[i] = temp;                      
      Instantiate(cube,theOpenList[i].celPos,transform.rotation); 
 }
Comment
Add comment · Show 1 · 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 meat5000 ♦ · Nov 19, 2014 at 07:14 PM 0
Share

Works beautifully.

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

C# custom class array error in adding a new entry. 1 Answer

Error message when accessing class array 1 Answer

Boo: Object reference not set to an instance of an object 1 Answer

UNITY_MVP_MATRIX error when downloading A* Pathfinding 1 Answer

"Null Reference Error" when using a custom class as an array 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