XNA: Initialize and LoadContent not called
I am running into a weird problem. I have a class that inherits from DrawableGameComponent, and I have overridden the Initialize, LoadContent, UnloadContent, Update and Draw methods. Update and Draw are called as normal by XNA (i dont know who calls the methods exactly, but i know im not calling them explicitly). the weird part is Initialize, and LoadContent are never called.
What could be causing this?
Thanks
-Adam
When are you adding the component to your game? There is a bug in the XNA Game class in regards to adding components. If you add them in your game's Initialize method AFTER calling base.Initialize(), they won't be automatically initialized and you'll have to do that yourself. If you add them before base.Initialize() or after the game has started the Update/Draw loop, the game automatically initializes them.
in all of my methods, i have the call to the base method at the very end ie base.Initialize() shows up at the very end of my overridden Initialize method.
i looked through my code a little and found something that might be a culprit but im not sure. here is a simple example:
to help elaborate (if necessary) GameState is used in a GameStateManager which inherits from DrawableGameComponent. the GameStateManager is setup in Game.cs in the method Initialize and before base.Initialize() is called.
i looked through my code a little and found something that might be a culprit but im not sure. here is a simple example:
class GameState : DrawableGameComponent{...}class Menu : DrawableGameComponent{...}class TestState : GameState{ public Menu menu; // could this be a part of the problem?}
to help elaborate (if necessary) GameState is used in a GameStateManager which inherits from DrawableGameComponent. the GameStateManager is setup in Game.cs in the method Initialize and before base.Initialize() is called.
I really don't recommend having GameState inherit from DrawableGameComponent. A gamestate isn't something that's rendered. I highly recommend you take a look at the GamestateManagement sample on the CC forums.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement