internal Attachment(IntPtr ptr, EntityBase owner) { Owner = owner; Owner.OnDestroyed += (instance) => { NativeEntityMethods.RemoveEntity(Id, false); }; this.SetIAttachment(ptr); string attachmentObject = NativeEntityMethods.GetAttachmentObject(this.GetIAttachment()); var tempEntity = Entity.Spawn("AttachmentEntity", typeof(NativeEntity).Name); Id = tempEntity.Id; this.SetIEntity(tempEntity.GetIEntity()); ScriptManager.Instance.ReplaceScriptInstance(this, tempEntity.ScriptId, ScriptType.Entity); EntityAttachmentHandle = NativeEntityMethods.LinkEntityToAttachment(this.GetIAttachment(), Id); if (!String.IsNullOrEmpty(attachmentObject)) // Just in case it had a model loaded by default { LoadObject(attachmentObject); } }