• 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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



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

Cannot cast from source type to destination type 1 Answer

Cant assign variables of a custom class 1 Answer

Adding a class with Generic Lists inside a Generic List 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges