Jump to content

  • Log In with Google      Sign In   
  • Create Account

Problem loading content folder automatically


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 gchewood   Members   -  Reputation: 236

Like
0Likes
Like

Posted 27 November 2012 - 06:17 AM

I'm writing a level editor for XNA and would really like to be able to load all of the models in my content folder automatically (so I can add new content without having to write new code).

I'm basing my code on that found in this article:
http://danielsaidi.w...es-in-a-folder/
though I've adjusted it slightly for my own purposes.

Here's the method I'm using:

public void LoadContent(ContentManager contentManager, List<Model> li)
		{
	
			DirectoryInfo dir = new DirectoryInfo(contentManager.RootDirectory);
			if (!dir.Exists)
				throw new DirectoryNotFoundException()
			FileInfo[] files = dir.GetFiles("*.fbx");
			foreach (FileInfo file in files)
			{
				string key = Path.GetFileNameWithoutExtension(file.Name);
				li.Add(contentManager.Load<Model>(key));  
			}
		}

The code runs just fine but doesn't add any model files to the list. There are definitely 4 fbx files in my content folder. I even tried adding them in the project (which I'd assumed wouldn't be necessary). Hope someone can help me out, I really don't wanna have to constantly change the code!
Thanks

Sponsor:

#2 kubera   Members   -  Reputation: 916

Like
0Likes
Like

Posted 27 November 2012 - 07:08 AM

You would have an invalid path.
Please consider checking contentManager.RootDirectory.

#3 gchewood   Members   -  Reputation: 236

Like
0Likes
Like

Posted 27 November 2012 - 07:45 AM

Not entirely sure what you're saying. How would my path be invalid? I set the rootdirectory and use it to load content elsewhere in the project so I somehow doubt that's the problem.
Also, that would throw the DirectoryNotFoundException(). Which it doesn't.

#4 MisterFuzzy   Banned   -  Reputation: 161

Like
0Likes
Like

Posted 27 November 2012 - 09:47 AM

The root usually isn't your Content folder, it's the application root... So you still need to navigate to your content folder. This may or may not be the case (I usually have to set the directory myself), but try printing a debug string with the value "content.RootDirectory" to see where it's going.

"Only idiots quote themselves" - MisterFuzzy

 


#5 gchewood   Members   -  Reputation: 236

Like
0Likes
Like

Posted 27 November 2012 - 11:00 AM

I set content.RootDirectory in the game's constructor (as I thought was done everyone) and it's used to load all of the others game content so that's definitely not the problem.

#6 phil_t   Crossbones+   -  Reputation: 3914

Like
0Likes
Like

Posted 27 November 2012 - 12:53 PM

Yeah, it should be the content folder, so you're good there. You're sure the files are there in the output Content folder? (e.g. [yourgame]/bin/x86/Debug/Content/....)

You said you added them to the content project - but what did you do to ensure they end up getting copied to the output Content folder? By default, "Copy to Output Directory" is set to "Do not copy". Make sure you've changed it to "Copy if Newer".




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS