Home > Back-end >  How does Unity's start and update work? And how can I replicate it in pure c#?
How does Unity's start and update work? And how can I replicate it in pure c#?

Time:04-02

I am making a 2d game engine (just a challenge. I'm not going to make it public) and experiencing problems:

How can I make start and update methods?

And before I started making the engine I used Unity so I kind of know Unity.

I tried using abstract methods, but the problem with abstract methods is that they're kind of not easy to use and you have to use all the abstract methods all at once if they are in an abstract class so I went to back what I know, Unity, and here I am writing this question. So how can I replicate Unity's start an update methods?

CodePudding user response:

Most of Unity's engine is actually written in C and they use some complex reflection to determine which of the event functions each script inheriting from MonoBehaviour has implemented post-compilation. This being the case I'm not sure it's possible to replicate it exactly in pure C#.

There's an interesting discussion of some of the details on Unity Answers, but to be honest my suggestion would be to give up on replicating their system precisely and find an alternative event system that accomplishes the same basic goals using overrides or perhaps delegates.

CodePudding user response:

Here is my input to this situation, fairly new to unity myself, but as far as i know start will trigger and initialise when the play button is hit.

Update will "update" or check its contents for change once per frame.

As far as replicating in pure C#, that is probably outside the bounds of my knowledge

  • Related