Generic Interface- C# Skill in Unity: 9

Objective: creating generic Interface to handle different implement with one Interface.

We had introduced about Interface and abstract class in the previous tutorials. They are all pretty handy tools to create the core function of your game. In this tutorial, we will dig a little bit deeper about using generic interface.


As we know, an Interface will not contain anything but properties and methods, and you can set the variable for methods. However, if this Interface would be implemented to many classes, you might need to set multiple variables to same method.

And it would reveal in options when you want to call a method is implemented from an Interface.

This would cause some troubles on classes that implement this Interface. Therefore, we will need to use generic Interface to solve this problem.

Setting generic

First we need to make our Interface as generic type by adding T with brackets to its name.

And use T instead of variables of method.

That way you have define this method as generic type. When implement this Interface, you need to declare what type you would use in that class.

Using generic type of Interface

As we using this Interface, we would need to input the type in brackets of it.

And the implemented method would also use the type.

It would be much easier if you want to implement this method or Interface as another type.




A passionate gamer whose goal is to work in video game development.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

The beginning of Alibaba Summer Of Code 2020

Introduction to why you should learn SQL

Take your candidate screening to the next level with this conversational AI app

What Is WordPress? Explained for Beginners.

Designing Micro Frontend with Web Components

Let Magic Be Magic

My Experience in KWoC 2020

Overview to Helm

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
S.J. Jason Liu

S.J. Jason Liu

A passionate gamer whose goal is to work in video game development.

More from Medium

Generating A Semi-Random 2D Platformer Level

Tips to Improve Unity Performance

How to use Post Processing in Unity

Unity Dev Blog: Adjusting Gameplay Mechanics