- Home /
Question by
HwangTaejunSkyPeople · Aug 10, 2021 at 10:42 AM ·
assetbundlebundleaddress
How can I cast as a game object? Addressable LoadResourceLocationsAsync locationsAsync
public async Task<T> LoadLocationsAsync<T>(string address) where T : Object
{
var handle = Addressables.LoadResourceLocationsAsync(address);
var locations = await handle.Task;
Addressables.InstantiateAsync(locations[0]);
return locations[0].Data as T;
}
In the sample code above, the instance is well created, but location[0].Data is null. I want to cast as GameObject and pass the return value. What should I do?
Comment
Answer by Nistroy · Aug 10, 2021 at 06:45 PM
Simply replace as T with as GameObject
public async Task<T> LoadLocationsAsync<T>(string address) where T : Object
{
var handle = Addressables.LoadResourceLocationsAsync(address);
var locations = await handle.Task;
Addressables.InstantiateAsync(locations[0]);
return locations[0].Data as GameObject;
}
location[0].Because Data is null, I think we need to resolve the issue where Data is null.
Your answer
Follow this Question
Related Questions
Addressables.ClearDependencyCacheAsync Exception 0 Answers
questions about addressables 0 Answers
Sprite in Asset Bundles returned a Texture2D 3 Answers
Addressable Assets integer Addresses? 0 Answers