Question by
PridesFall08 · Apr 03, 2019 at 01:31 PM ·
referenceoutthis
Cannot use 'this' as a ref or out value because it is read-only | (kinda)SOLVED
I was having a problem where if I would do HandItem.Unequip(ref this);
, where this
is an ItemUser
interface, I would get an error from visual studio saying:
Cannot use 'this' as a ref or out value because it is read-only
, but I've found a solution: instead of using this
I tried using an auxiliary declaration and set the properties of this
to be that of the other ItemUser
:
ItemUser IU = this;
HandItem.Unequip(ref IU);
Hand = IU.Hand;
HandItem = IU.HandItem;
PocketItem = IU.PocketItem;
This way it works. Hope I helped someone today :)
Comment
Your answer
Follow this Question
Related Questions
Store a reference to a variable instead of just the value in a class? 1 Answer
How to find (and remove) references to GameObject C# 0 Answers
What are some best practices for static variables in multiplayer? 0 Answers
Why is the this object referenced to itself? 1 Answer
Inspector removing references? 1 Answer