I ran into what I believe was the same issue after upgrading Unity from 2021.3.5f1
to 2021.3.38f1
. The AvatarCreatorWizard would fail after choosing an avatar template with the message "We failed to load the photo (we bet you look great, though)! Please try using a different file."
even though the photo selection was never attempted. This only ever occurred in builds, never in the editor.
The issue was very hard to reproduce, and didn’t occur when importing the SDK into an empty project. Sometimes, changing seemingly random things would fix it.
It seems that for whatever reason, the "id"
field in the response from AvatarAPIRequests.GetAvatarTemplates()
was no longer deserializing correctly, which caused the later code to incorrectly assume that you didn’t choose a template and are trying to create an avatar from a photo (even though no photo was ever taken, resulting in the API call failure). I confirmed this with a minimal code sample like this:
var data = "{\"imageUrl\":\"https://readyplayerme-avatars.s3.amazonaws.com/avatar-template-images/white-female-1.png\",\"id\":\"645cd1cef23d0562d3f9d28d\"}";
var x = JsonConvert.DeserializeObject<AvatarTemplateData>(data);
Debug.Log("Does this work? id=" + x.Id + " imageUrl=" + x.ImageUrl);
Which printed:
Does this work? id= imageUrl=https://readyplayerme-avatars.s3.amazonaws.com/avatar-template-images/white-female-1.png
After a few hours of debugging I figured out that Unity is likely somehow striping out the Id
property setter because it thinks it’s unused. Other strings in the class worked because they were fields, rather than properties. Changing the Managed Stripping Level
in Project Settings > Player
from the default of Low
to Minimal
seems to have fixed the issue.
Alternatively, you can create a file called link.xml
anywhere within your Assets
hierarchy with the following contents, to force Unity to never strip the RPM assemblies, which seems to work just as well:
<!-- Workaround an issue after Unity 2021.3.5f1 -> 2021.3.38f1 upgrade where some of the JSON serializable properties get stripped randomly -->
<linker>
<assembly fullname="ReadyPlayerMe.Core" preserve="all"/>
<assembly fullname="ReadyPlayerMe.AvatarCreator" preserve="all"/>
</linker>
(listing the serializable types explicitly, or using preserve annotations in the code would be even better, but I didn’t want to bother with that)