in packages/sdk/src/core/contextInternal.ts [125:204]
private createActorFromPayload(
payload: Payloads.CreateActorCommon
): Actor {
// Resolve by-reference values now, ensuring they won't change in the
// time between now and when this message is actually sent.
payload.actor = Actor.sanitize(payload.actor);
// Create the actor locally.
this.updateActors(payload.actor);
// Get a reference to the new actor.
const actor = this.context.actor(payload.actor.id);
// check permission for exclusive actors
let user: User;
if (actor.exclusiveToUser) {
user = this.userSet.get(actor.exclusiveToUser);
if (user.hasGrantedPermissions &&
!(user.grantedPermissions.includes(Permissions.UserInteraction))) {
actor.internal.notifyCreated(false,
`Permission denied on user ${user.id} (${user.name}). Either this MRE did not ` +
"request the UserInteraction permission, or it was denied by the user.");
}
}
// check permission for attachments
if (actor.attachment?.userId) {
user = this.userSet.get(actor.attachment?.userId);
if (user.hasGrantedPermissions &&
!(user.grantedPermissions.includes(Permissions.UserInteraction))) {
actor.internal.notifyCreated(false,
`Permission denied on user ${user.id} (${user.name}). Either this MRE did not ` +
"request the UserInteraction permission, or it was denied by the user.");
}
}
this.protocol.sendPayload( payload, {
resolve: (replyPayload: Payloads.ObjectSpawned | Payloads.OperationResult) => {
this.protocol.recvPayload(replyPayload);
let success: boolean;
let message: string;
if (replyPayload.type === 'operation-result') {
success = replyPayload.resultCode !== 'error';
message = replyPayload.message;
} else {
success = replyPayload.result.resultCode !== 'error';
message = replyPayload.result.message;
for (const createdAnimLike of replyPayload.animations) {
if (!this.animationSet.has(createdAnimLike.id)) {
const createdAnim = new Animation(this.context, createdAnimLike.id);
createdAnim.copy(createdAnimLike);
this.animationSet.set(createdAnimLike.id, createdAnim);
}
}
for (const createdActorLike of replyPayload.actors) {
const createdActor = this.actorSet.get(createdActorLike.id);
if (createdActor) {
createdActor.internal.notifyCreated(success, replyPayload.result.message);
}
}
}
if (success) {
if (!actor.collider && actor.internal.behavior) {
log.warning('app', 'Behaviors will not function on Unity host apps without adding a'
+ ' collider to this actor first. Recommend adding a primitive collider'
+ ' to this actor.');
}
actor.internal.notifyCreated(true);
} else {
actor.internal.notifyCreated(false, message);
}
},
reject: (reason?: any) => {
actor.internal.notifyCreated(false, reason);
}
});
return actor;
}