Guidance with Asset spawning/AssetPool
Hi there, creators. For the past few days, I've been struggling to find an optimal way to spawn weapons and baskets for each player. Previously, before discovering the AssetPool Gizmo, i spawned each weapon and basket for each player. This worked, and to no surprise, it was really slow ( and now in the latest version of the desktop editor, it either locks up the UI trying to spawn or isn't visible in the editor). Utilizing the AssetPool Gizmo didn't lock up the UI; however, despite having a simple asset reference continues to return `undefined` instead of the spawned entity when i attempt to retrieve it from the pool. Could i be missing something? or is this Gizmo/ Asset Spawning buggy at the moment?
Code snippet
private spawnBasket(player: Player): void {
// Try pool first
if (this.basketPoolGizmo) {
const basket = this.basketPoolGizmo.getPooledEntity();
console.log(basket) // always seems to print undefined
if (basket) {
const attachable = basket.as(AttachableEntity);
if (attachable) {
attachable.attachToPlayer(player, AttachablePlayerAnchor.Torso);
attachable.socketAttachmentPosition.set(new Vec3(0, 0, -0.5));
}
this.playerPooledBaskets.set(player.id, basket);
console.log(`GameManager: Basket attached (pooled) for ${player.name.get()}`);
return;
}
}
From the documentation for the getPooledEntity() method:
Get an entity from the Asset Pool. Will only return entities in Default (not Local) execution scripts.
Signature
getPooledEntity(): Entity | undefined;
Returns
Entity | undefined
A pooled entity if the pool still has one available, or undefined if not.
Since the Asset Pool is set to use Auto Assign to Players and Auto Pool Size, I suspect that there are only enough Assets for each player and the assets are already assigned, so the Asset Pool returns undefined and does not attempt to generate a new instance of the Asset at runtime. Try to disable Auto Assign to Players and Auto Pool Size to create a custom size pool for your needs for the asset, if you need more than one per player.