Follow

What is CS1612?

Symptoms

When trying to enter play mode, I am receiving the error below:

error CS1612: Cannot modify a value type return value of `__'. Consider 
storing it in a temporary variable.

Cause

The CS1612 error occurs because value types are copied on assignment. When you retrieve a value type from a property or indexer, you are getting a copy of the object, not a reference to the object itself. The copy that is returned is not stored by the property or indexer because they are actually methods, not storage locations (variables). 

The error displayed in this example: 

error CS1612: Cannot modify a value type return value of 
`UnityEngine.Transform.position'. Consider storing it in a
temporary variable.

Resolution

The error CS1612 is solved by storing the copy into a variable that you declare before you can modify it.

More Information

https://msdn.microsoft.com/en-us/library/wydkhw2c.aspx

 

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.