简体   繁体   中英

C# XNA Load Model Error

I tried to load a model in XNA using model = Content.Load<Model>("Ship"); in LoadContent() method ( public Model model; = i declared the model), but I get an exception:

An unhandled exception of type 'Microsoft.Xna.Framework.Content.ContentLoadException' occurred in Microsoft.Xna.Framework.dll

Additional information: Error loading "Ship". File contains Microsoft.Xna.Framework.Content.Pipeline.Graphics.NodeContent but trying to load as Microsoft.Xna.Framework.Graphics.Model.

What should I do?

PS I used a .x file and I also tried using a .fbx file.

PPS I saw a question with this line as a solution Content.RootDirectory = "Content"; and I already have it.

I found the solution! Click on your model in the Solution Explorer, and open its Properties window.

Find the XNA Framework Content Pipeline section

Asset Name: If Asset Name is empty, put something in it (for example if you are loading a car model put car in this field) and load it with the asset name like this

(model name here)=Content.Load<Model>("(Asset name)");

In the example above (car model) it will be

model=Content.Load<Model>("car"); //Declare a Model called model first

Content Importer: FBX models = Autodesk FBX - XNA Framework | X models = X File - XNA Framework

Content Processor: Model - XNA Framework

And that's it!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM