MonoBehavior implement interface with custom Update(float) method error

I have a class (let’s say MyBehavior) which uses MonoBehavior as base class and a interface (let’s say MyInterface) which has a Update(float) method.

I want to implement MyInterface in MyBehavior, but the problem is Unity thinks I want to implement the Unity Update(void) method instead of my interface Update(float) method and gives me an error “Update() can not take parameters”.

Is there any way to “tell” Unity that this is the interface Update(float) method and NOT the “magic” Unity Update(void) method, so that Unity ignores it? Maybe with an Attribute or something?

Btw it doesn’t matter if I implement the interface implicit or explicit, I get the same error in both cases.

Just stop trying to fight against the engine. Name your method something else. OnUpdate() is an option.

3 Likes

Doesn’t work if the interface is in a .dll and you don’t have access to the interface source code.

As a workaround I made a wrapper class (not a MonoBehavior) which has access to my behavior class and implements the interface.

1 Like