Solved. Sorry for the confusion guys, it was a Resharper false error. There was nothing wrong with my code. Thanks for anybody who tried to help.
Can't override GetHashCode (cannot change return type when overriding method int UnityEngine.Object.GetHashCode")
-
24-06-2022 - |
Вопрос
I'm using C# in Unity3D game engine. in my MonoBehaviour script I need to override GetHashCode
. But whenever I do, I get the error cannot change return type when overriding method int UnityEngine.Object.GetHashCode"
(Isn't GetHashCode located inside the System namespace?)
My overriding:
public override int GetHashCode()
{
return index.GetHashCode();
}
The error no longer exists if I remove the using UnityEngine;
header from the top. I tried to explicitly tell it what to override, it's not like dealing with interfaces, so it didn't work.
What's going on here, are there two GetHashCode
s? how can I override GetHashCode
here?
Thanks.
EDIT: I have removed the using System;
and left out UnityEngine
, same result.
EDIT: I also tried an empty class, and another project, nothing :(
Решение 3
Другие советы
UnityEngine.Object has its own GetHashCode() and to overwrite it you simply do what you've done above, except the return type you have there is wrong. See below:
public class Test : MonoBehaviour {
public override int GetHashCode() {
return base.GetHashCode();
}
}
.Net can't understand which Object you are using.
using Object=System.Object;
try this