bool FCollectionManager::RemoveFromCollection(FName CollectionName, ECollectionShareType::Type ShareType, const TArray<FName>& ObjectPaths, int32* OutNumRemoved)
{
	if ( OutNumRemoved )
	{
		*OutNumRemoved = 0;
	}

	if ( !ensure(ShareType < ECollectionShareType::CST_All) )
	{
		// Bad share type
		LastError = LOCTEXT("Error_Internal", "There was an internal error.");
		return false;
	}

	FCollection** CollectionPtr = CachedCollections[ShareType].Find(CollectionName);
	if (CollectionPtr != NULL)
	{
		FCollection* Collection = *CollectionPtr;
		
		TArray<FName> RemovedAssets;
		for (int32 ObjectIdx = 0; ObjectIdx < ObjectPaths.Num(); ++ObjectIdx)
		{
			const FName& ObjectPath = ObjectPaths[ObjectIdx];

			if ( Collection->RemoveAssetFromCollection(ObjectPath) )
			{
				RemovedAssets.Add(ObjectPath);
			}
		}

		if ( RemovedAssets.Num() == 0 )
		{
			// Failed to remove, none of the objects were in the collection
			LastError = LOCTEXT("Error_NotInCollection", "None of the assets were in the collection.");
			return false;
		}
			
		if ( Collection->Save(LastError) )
		{
			// Removed and saved
			if ( OutNumRemoved )
			{
				*OutNumRemoved = RemovedAssets.Num();
			}

			FCollectionNameType CollectionNameType( Collection->GetCollectionName(), ShareType );
			AssetsRemovedEvent.Broadcast( CollectionNameType, ObjectPaths );
			return true;
		}
		else
		{
			// Removed but not saved, revert the remove
			for (int32 AssetIdx = 0; AssetIdx < RemovedAssets.Num(); ++AssetIdx)
			{
				Collection->AddAssetToCollection(RemovedAssets[AssetIdx]);
			}
			return false;
		}
	}
	else
	{
		// Collection not found
		LastError = LOCTEXT("Error_DoesntExist", "The collection doesn't exist.");
		return false;
	}
}
bool FCollectionManager::AddToCollection(FName CollectionName, ECollectionShareType::Type ShareType, const TArray<FName>& ObjectPaths, int32* OutNumAdded)
{
	if ( OutNumAdded )
	{
		*OutNumAdded = 0;
	}

	if ( !ensure(ShareType < ECollectionShareType::CST_All) )
	{
		// Bad share type
		LastError = LOCTEXT("Error_Internal", "There was an internal error.");
		return false;
	}

	FCollection** CollectionPtr = CachedCollections[ShareType].Find(CollectionName);
	FCollection* Collection = NULL;
	if (CollectionPtr != NULL)
	{
		Collection = *CollectionPtr;
	}
	else
	{
		// Collection doesn't exist
		LastError = LOCTEXT("Error_DoesntExist", "The collection doesn't exist.");
		return false;
	}

	if ( ensure(Collection) )
	{
		int32 NumAdded = 0;
		for (int32 ObjectIdx = 0; ObjectIdx < ObjectPaths.Num(); ++ObjectIdx)
		{
			if ( Collection->AddAssetToCollection(ObjectPaths[ObjectIdx]) )
			{
				NumAdded++;
			}
		}

		if ( NumAdded > 0 )
		{
			if ( Collection->Save(LastError) )
			{
				// Added and saved
				if ( OutNumAdded )
				{
					*OutNumAdded = NumAdded;
				}

				FCollectionNameType CollectionNameType( Collection->GetCollectionName(), ShareType );
				AssetsAddedEvent.Broadcast( CollectionNameType, ObjectPaths );
				return true;
			}
			else
			{
				// Added but not saved, revert the add
				for (int32 ObjectIdx = 0; ObjectIdx < ObjectPaths.Num(); ++ObjectIdx)
				{
					Collection->RemoveAssetFromCollection(ObjectPaths[ObjectIdx]);
				}
				return false;
			}
		}
		else
		{
			// Failed to add, all of the objects were already in the collection
			LastError = LOCTEXT("Error_AlreadyInCollection", "All of the assets were already in the collection.");
			return false;
		}
	}
	else
	{
		// Collection was never found. Perhaps it was null in the TMap
		LastError = LOCTEXT("Error_DoesntExist", "The collection doesn't exist.");
		return false;
	}
}