I am attempting to load a prefabs (Projectile.prefab) from another AssetBundle (gun.unity3d). All the sprites and SpriteAtlas that are being used by the Projectile prefab are in another AssetBundle (vfx_projectiles.unity3d).
The problem I am having is that the sprite is never shown on the prefab. This happens with other SpriteAtlas I am using in the project. If I delete the SpriteAtlas from the project and AssetBundle, I can see the Sprite on the prefab(s). I am using Unity 2017.1.0p5
When I load the projectile, the sprite is missing. But the image is assigned:

And I get this error when I click on the sprite via the SpriteRenderer:
Also I get another error when I load the Unity scene where the assetbundle and prefab are needed:
In the Editor,
All the sprites are tagged with the Atlas name i.e (Projectiles)
I also unchecked including the SpriteAtlas in a build, therefore; I should be loading it through an AssetBundle and/or resources

Then I wait for my services to load, and attempt to load the atlases. This is during boot/load time of the application:
/// <summary>
/// Loads sprite atlases from assets bundles
/// </summary>
public sealed class AtlasLoader : SBMBehaviour, IAtlasLoader
{
#region Members
/// <summary>
/// Reference to the resource service
/// </summary>
private IResourceService _resourceService;
/// <summary>
/// Reference to the asset bundle service
/// </summary>
private IAssetBundleService _assetBundleService;
/// <summary>
/// Collection of the sprite atlases and their callbacks to load
/// </summary>
private Dictionary<string, Action<SpriteAtlas>> _spriteAtlasToLoad;
#endregion
#region Injection
/// <summary>
/// Inject the resource service
/// </summary>
[Inject]
public IResourceService ResourceService { get { return _resourceService; } set { _resourceService = value; } }
/// <summary>
/// Inject the asset bundle service
/// </summary>
[Inject]
public IAssetBundleService AssetBundleService { get { return _assetBundleService; } set { _assetBundleService = value; } }
#endregion
#region Life Cycle
/// <summary>
/// Allocate members and register for event
/// </summary>
protected override void Awake()
{
base.Awake();
_spriteAtlasToLoad = new Dictionary<string, Action<SpriteAtlas>>();
SpriteAtlasManager.atlasRequested += OnSpriteAtlasRequested;
}
/// <summary>
/// Initialize members
/// </summary>
public void Initialize()
{
if (_resourceService == null)
LogError("Resource service not initialized!");
}
/// <summary>
/// Load SpriteAtlases if requested
/// </summary>
private void Update()
{
if (_spriteAtlasToLoad != null && _spriteAtlasToLoad.Count > 0 && _resourceService != null && _assetBundleService != null && _assetBundleService.Loaded) {
foreach (KeyValuePair<string, Action<SpriteAtlas>> pair in _spriteAtlasToLoad) {
string tag = pair.Key;
Action<SpriteAtlas> onAtlasLoaded = pair.Value;
string assetbundle = AssetBundleUtility.GetAssetBundleName(AssetBundleType.vfx, tag);
Log("Attempting to load atlas: {0} in AB: {1}", tag, assetbundle);
_resourceService.GetAsset<SpriteAtlas>(assetbundle, tag, (spriteAtlas) => {
onAtlasLoaded(spriteAtlas);
});
}
_spriteAtlasToLoad.Clear();
}
}
/// <summary>
/// Unregister for the event
/// </summary>
private void OnDestroy()
{
if (_spriteAtlasToLoad != null && _spriteAtlasToLoad.Count > 0)
_spriteAtlasToLoad.Clear();
SpriteAtlasManager.atlasRequested -= OnSpriteAtlasRequested;
}
#endregion
#region Event Handling
/// <summary>
/// Handle the event when an atlas is requested
/// </summary>
/// <param name="tag">tag name of the sprite atlas</param>
/// <param name="onAtlasLoaded">callback after atlas has been loaded</param>
private void OnSpriteAtlasRequested(string tag, Action<SpriteAtlas> onAtlasLoaded)
{
Log("Loading Sprite atlas! SpriteAtlas: {0}", tag);
if (_spriteAtlasToLoad != null && !_spriteAtlasToLoad.ContainsKey(tag))
_spriteAtlasToLoad.Add(tag, onAtlasLoaded);
}
#endregion
}
After doing all this, I tried to get the same sprite from the loaded Atlas via SpriteAtlas.GetSprite. It came back as a valid sprite and the same NullReferenceException occurred.
