Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Need help with virtual void

Discussion in 'Scripting' started by ozoromo, Mar 23, 2020.

  1. ozoromo

    ozoromo

    Joined:
    Nov 6, 2017
    Posts:
    4
    I'm trying to make use of virtual voids but for some reason, unity isn't finding the virtual void

    Script 1 (the one where the virtual void is created):
    Code (CSharp):
    1.     public virtual void Interact () {
    2.         Debug.Log("I got called");
    3.     }
    and this is script 2 (the one that can't find the virtual void and can therefor not overwrite it) :
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class DoorSystem : MonoBehaviour {
    6.  
    7.     public override void Interact () {
    8.         base.Interact
    9.         }
    10. }
    11.  
    The error I get from Unity is: 'DoorSystem.Interact()' is marked as an override but no suitable method found to override

    I'm kind of new to this so it might be an obvious error, but could someone please help me fix it?

    -ozoromo ;)
     
  2. ozoromo

    ozoromo

    Joined:
    Nov 6, 2017
    Posts:
    4
    ps: Script 1 is only a snippet of the entire script (just to make sure that there are no misunderstandings)
     
  3. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,748
    DoorSystem needs to inherit whatever class has the virtual void (right now it inherits from MonoBehaviour).
     
    willemsenzo likes this.
  4. willemsenzo

    willemsenzo

    Joined:
    Nov 15, 2012
    Posts:
    585
    Your DoorSystem class inherits from MonoBehaviour and not from the base class.
     
  5. ozoromo

    ozoromo

    Joined:
    Nov 6, 2017
    Posts:
    4
    You are saint, thanks for the lightning speed reply!
     
  6. ozoromo

    ozoromo

    Joined:
    Nov 6, 2017
    Posts:
    4
    Thanks to you too for the quick help