Why use base.Initialize(), base.Draw() and base.Update() anymore?

Hi! I have a question for you guys about the base.Initialize(), base.Draw() and base.Update() methods.

From what I read in the documentation, calls to base.Initialize(), base.Draw() and base.Update() are included in the Initialize(), Draw() and Update() methods of the main class for the sake of initializing, updating and drawing all Game Components. However, I’ve seen opinions on StackExchange a while back (sorry, I’m not able to find these posts anymore so no link) that Game Components are obsolete, and it’s not a good idea to rely on them. I think it had something to do with you having no control over the order in which the components are updated and drawn.

Soooo, is there any point to calling these base methods anymore?:sweat_smile: From what I can see the base.Draw() and base.Update() calls can be omitted with no further action required, and if you manually call LoadContent() at the end of Initialize(), you can omit calling base.Initialize() as well. Is there any other reason for calling those?

Thanks in advance for your replies :relaxed:

The GameComponent stuff is not obsolete. I don’t think many people use it though, and that’s fine. You don’t have to call Game.Update and Game.Draw if you don’t use GameComponents, but I recommend you keep the base call in Initialize because that creates the GraphicsDevice.

Thanks a lot for the comment mate.

I did read somewhere that Initialize() creates the GraphicsDevice, so I did it manually and everything seems to be working fine.

Do you yourself use Game Components? For some reason I was convinced they are almost - if not entirely - out of use, but I’m not sure what I was basing this on :sweat_smile: I did try to include them in my architecture once, but it annoyed me that their Update() and Draw() functions are being called somewhere implicitly, and it was hard to say just from looking at the code what is happening where and why.

I never used to use them but I have started to. For example I have my own keyboard API that can detect presses, clicks, double clicks etc. In order to use it in a project it’s one line of code. That’s it no messing with calling the update for it.

Also as for the draw or update order. Wherever your base.draw or base.update is called it will then process the components in the order you added them.

1 Like

@mohaxomaxa I don’t use GameComponents except in some rare cases (e.g just like Mattlekim for an input manager so it’s a one-liner: Components.Add(new Input(this)) ). I dislike GameComponents too, for the same reason as you :stuck_out_tongue:

They’re sorted by their UpdateOrder and DrawOrder using List.Sort. I’m not sure if the draw and update order is consistent for equal values, because List.Sort does an unstable sort.

1 Like