Nerd Herder

Dean Johnson blogs about life on the XNA platform and tools team

AvatarDescription.IsValid… When & Why the description returned is invalid?

AvatarDescription.IsValid… When & Why the description returned is invalid?

Rate This
  • Comments 4

In previous posts I talked about how the AvatarDescription contains data to define what an avatar should look like so that the AvatarRenderer knows what assets to load in order to render the avatar. The AvatarDescription type contains a property called IsValid which is a read only bool. So what does this property tell the developer? It tells the developer if the description is valid of course! So when can a developer expect a description to be valid and invalid?

First let’s go over the different ways a user can create an AvatarDescription object.

Gamer.SignedInGamers[PlayerIndex.One].Avatar – Returns the avatar description from a gamers profile.

AvatarDescription.CreateRandom() – Returns a randomly created avatar description.

AvatarDescription(byte[] data) – Constructor that allows the developer to construct a description from a byte[] that was returned from the AvatarDescription.Description property of an already created AvatarDescription object. A future post will talk more about this constructor and why it is useful.

Now for the rules on when descriptions are valid vs. invalid.

· On Windows the profile and random avatar descriptions will return as invalid descriptions because Windows does not support avatars.

· On Xbox the random avatar description will return valid descriptions.

· On Xbox the profile avatar description can return both valid and invalid descriptions. If a user does not have an avatar associated with their profile then the avatar description returned will be invalid.

Not too confusing right?

So how do invalid AvatarDescriptions behave?

The properties on the AvatarDescription such as the Height, BodyType, and Description return default values. IsValid returns false as you would expect.

So what happens if you use an invalid AvatarDescription to create an AvatarRenderer? Does it throw an exception? No. You will get back an AvatarRenderer object. You can do everything that you would do normally with an AvatarRenderer created with a valid AvatarDescription. The difference is when you call draw nothing will be displayed to the screen. This was done so that while you develop your game on Windows you will not need to wrap all of your AvatarRenderer constructor or draw calls in try/catch statements. While the avatar will not draw on Windows there is also a chance that the users profile on the Xbox will also be invalid. The developer should detect that the game can’t display an avatar and do something appropriate. For example the developer may create a stand in model to use when a user doesn’t have a valid avatar description.

Page 1 of 1 (4 items)
Leave a Comment
  • Please add 1 and 4 and type the answer here:
  • Post
Translate This Page