I'm trying to move my project to Addressables and upload assets, prefabs and screens to an archive on the server.
I'm a new in Unity and this a bit challenging for me.
I've prepared all prefabs for addressable usage and now I'm trying load them.
All my prefabs have loads throw GameObject.Instantiate
For example:
public class PlatformObject : LocationObject
{
//other properties and methods
public PlatformObject Clone()
{
var clone = ((Runner.PlatformObject)GameObject.Instantiate(this));
clone.Id = this.Id;
clone.NextPlatforms = this.NextPlatforms;
clone.IsStartPlatform = this.IsStartPlatform;
clone.Level = this.Level;
clone.Type = this.Type;
clone.MinimumDistance = this.MinimumDistance;
clone.AllowDispose = false;
clone.Size = this.Size;
return clone;
}
}
I've tried change this code for usage Addressables
.
public async Task<PlatformObject> Clone()
{
var handle = Addressables.LoadAssetAsync<GameObject>(this.name);
var clone = (await handle.Task).GetComponent<PlatformObject>();
clone.Id = this.Id;
clone.NextPlatforms = this.NextPlatforms;
clone.IsStartPlatform = this.IsStartPlatform;
clone.Level = this.Level;
clone.Type = this.Type;
clone.MinimumDistance = this.MinimumDistance;
clone.AllowDispose = false;
clone.Size = this.Size;
return clone;
}
I've got a cloned object successfully, but object doesn't appears on the scene. Looks like object not initialized properly, bcouz I've got a lot of warnings like that:
Setting the parent of a transform which resides in a Prefab Asset is disabled to prevent data corruption (GameObject: 'Mid_Town_07'). UnityEngine.Transform:set_parent(Transform)
I've googled and have found a few solution related with parent location. Made changed but it didn't help. I'm still getting those warnings.