What is the purpose of this function? "protected virtual void Init() { }"

Hello, I’m a novice coder and don’t quite understand all the articulates of C#, so when I look at other people’s source code to learn from it some things I don’t quite understand.

The one I’m looking at in particular is [Dani’s LudumDare 45 vlog][1]

[Here is the source code for his “Actor” script I’m looking at][2]

I’m currently trying to make a 2D game which contains player’s and enemies and I understand that you can have one script with multiple declaring variables for that particular group of actors to save on coding.

On line 35 - 43 there’s a particular function that is called which I’m failing to understand the purpose of, here is a snippet of that particular code

    protected virtual void Init() { }

    private void Awake() {
        ps = GetComponentInChildren<ParticleSystem>();
        em = ps.emission;
        rb = GetComponent<Rigidbody2D>();
        sr = GetComponent<SpriteRenderer>();
        dColor = sr.color;

An “Init” function is I assume, overwritten but there’s no parameters or code in the actual function and then is called in the “Awake” function. What is the purpose of this function? As well as what benefit is having the function be protected? Thanks in advanced
[1]: Making a Game in 2 DAYS! - YouTube
[2]: LudumDare45/LD45/Player/Actor.cs at master · DaniDevy/LudumDare45 · GitHub

Well, because PlayerMovement as well as Enemy are derived from Actor and override the Init method. This is just basic / fundamental OOP, so I’m not sure what kind of answer or explanation you expect to get. The base class implements a virtual method that can be overridden by a derived class to provide additional / customized initialization code.

protected is just the visibility of that method. So this method can not be seen or called from outside the Actor class or any descendents because it’s only relevant for the internal function of this class / those classes. In general you should have everything either private or protected by default and only make things public that really need to be public.