ā How to create class like MonoBehaviour from Unity
I want to learn how to create a class like that, where the functions CAN be implemented but don't have to, how to have for example start function that doesn't need to be specifically implemented in the extending class
25 Replies
so, when using abstract, I need to implement it but using virtual I don't? and when I'm calling the function from another script would it return error or something?
Zeth
REPL Result: Failure
Exception: CompilationErrorException
Compile: 298.665ms | Execution: 0.000ms | React with ā to remove this embed.
I know, but with the virtual, if it doesn't need to be implemented wouldn;t it throw error as unimplemented function?
virtual means it can be overridden
object.ToString()
is virtual, for exampledo I need to sprecify the override?
yes
and how to they make it that u don't have to specify the override
abstract, with a concrete implementation in a child class
actually, no, that still needs an override.
so how do I go about making the derived class not use override?
you don't. Unity is magic.
remember, unity isnt real C#
but why does it matter?
whats wrong with having to write
override void Start()
?IDK really, I just wanted to know how to create it without the override
in that case, write your own runtime that can do whatever it wants with the IL that C# compiles to š
thats what Unity did
that may be a bit out of my scope š
It is for 99.9999% of people, I'd say
The rest of us, we use
override
^
this would force it to be addedThanks, I'm gonna use the virtual one as sometimes I won't need all the functions
This would not:
yeah
now the easy part, create a 3D renderer š
trivial
š
š
i mean, I did it before, how hard can it be to do it again? š
this time in C# instead of Java ofc š
I have done silly stuff like implementing a crude 3d renderer in a console app. Do not do this.
It is stupid.
well, I need some sort of engine after what unity has done and this may only benefit me as I would have complete control over what's going on, nevertheless I could do this for a school work for my class graduation, I might just learn something š
sure!
ambitious, but why the hell not
I have two years to complete it, so I hope it's enough time š
if u want to avoid virtual methods and want to force certain shapes of methods for functionality, u could use interfaces as well.
depending on how fine grained u want them, this could cause a lot of interfaces, then depending how u design the game loop the order would matter as well, because for casting/type checks the look up for if a type implements an interface is O(n)
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.