0
votes

I've been using this static TextureManager class that allows you to call textures you load in through the class. However, this time in a different project, it's unable to find the texture files and therefore keeps throwing null reference errors.

LoadContent in TextureManager class:

    public static void LoadContent(ContentManager content)
    {
        Monster1 = content.Load<Texture2D>(@"Textures/IfritHead");
        Monster2 = content.Load<Texture2D>(@"Textures/DragonHead");
    }

1. My content.rootdirectory in game1(not sure if this matters) is set to "Content".

2. I have added the texture files into the content pipeline(I'm assuming there is some problem here, but as I've mentioned before, I've used this class before but I still can't find the problem)

3. I have set the properties settings for the textures to "Copy if newer".

4. I read somewhere that reinstalling XNA might help, is this true?

5. I have used this class in other projects before and it works completely fine.

6. I'm using VS 2015 and XNA 3.0 if that helps with anything.

Does anyone know how to properly import assets? I'm not sure if I'm missing something very obvious...

1
You mention you are using XNA but you added the monogame tag to the question. Is this an XNA or Monogame project template? - Nahuel Ianni
Monogame template, I was under the impression that they were the same thing, but after a quick google monogame turns out to be rewritten to behave like XNA. - John Tran
Monogame wraps up the XNA functionality and builds upon it. In order to use Monogame, you have to have XNA installed as well (or used to be like this when I was using it). Thing is, it is not uncommon for people to have issues when importing textures in Monogame, so the question is: Which one are you using? - Nahuel Ianni
Try updating your textures' Properties -> Build Action -> Content - GMich
@GMich It was set as default. Sorry for late reply. - John Tran

1 Answers

0
votes

First, you should consider to switch to MonoGame instead of using (very) outdated XNA. Second, this is a quite common issue people run into. Besides the checks you already have mentioned, are the files copied in the content folder? In your case it should be Content/Textures/[your texture]

You said, you are using the pipeline tool. Have you built the xnb files properly or does the tool report any issues during the build?