# Blueprint インテグレーション

> Learn how to implement authentication using Unreal Engine Blueprints.

### Authentication SDK を依存関係として追加する##add-the-authentication-sdk-as-a-dependency

以下のブループリントデモンストレーションを進める前に、Authentication SDK プラグインが正常にインストールされていることを確認してください。また、Blueprint のイベントグラフや関数で、**Unity Gaming Services** > **Authentication** の下に Authentication 関連の関数が表示されることを確認してください。


**このブループリント用のすべてのアクション。:**
![このブループリント用のすべてのアクション。](/api/media?file=/authentication-unreal/media/images/unreal-auth-blueprint-actions.png)

#### Sign In Anonymously##sign-in-anonymously

`Sign In Anonymously ` を使用すると、[匿名で認証する](/authentication/use-anon-sign-in.md) ことができます。これは、ユーザー情報を必要とせず、外部プロバイダーとのインタラクションも不要な簡単な認証方法です。成功すると、Unity Authentication サーバーから返される認証情報で現在のプレイヤープロファイルが更新されます。

`Sign In Anonymously` は、サインインの実行方法を変更するパラメーターとして `FAuthenticationSignInOptions` 構造体を受け取ります。これらのパラメーターの詳細については、[Unity API サービスの公式ドキュメントページ](https://services.docs.unity.com/player-auth/v1/index.html) を参照してください。

SDK からの応答はカスタムイベントで処理できます。その際、[Authentication Response](./sdk-api/authentication/models/authentication-response.md) を出力ピンとして受け取る必要があります。応答変数を分割するには、応答本文の出力ピンを右クリックして **Split Pin** を選択します。


**Sign in anonymously:**
![Sign in anonymously](/api/media?file=/authentication-unreal/media/images/unreal-auth-sign-in-anonymously.png)

### Get User Info##get-user-info

`Get User Info` を使用すると、現在認証されているユーザーに関する情報を取得できます。これには、ユーザー ID、認証タイムスタンプ、およびそのセッションにリンクされている外部 ID プロバイダーが含まれます。

SDK からの応答はカスタムイベントで処理できます。その際、Authentication SDK からのユーザー応答を表す [Authentication User Response](./sdk-api/authentication/models/authentication-user-response.md) を出力ピンとして受け取る必要があります。応答変数を分割するには、応答本文の出力ピンを右クリックして **Split Pin** を選択します。


**Get user info:**
![Get user info](/api/media?file=/authentication-unreal/media/images/unreal-auth-user-info.png)

### Delete User##delete-user

`Delete User` を使用すると、現在認証されているプレイヤーに関連するすべての情報を削除できます。この関数は、プレイヤーをサインアウトし、プレイヤーの設定やプロファイルもすべて削除します。

SDK からの応答はカスタムイベントで処理できます。その際、削除が成功したかどうかを示す `Boolean` を出力ピンとして受け取る必要があります。


**Delete user:**
![Delete user](/api/media?file=/authentication-unreal/media/images/unreal-auth-delete-user.png)

### Register State Changed Callback##register-state-changed-callback

`Register State Changed Callback` を使用すると、[サブシステムの状態](./authentication-lifecycle.md) が変化した際に呼び出されるコールバック関数を割り当てることができます。例えば、プレイヤーが認証に成功してサブシステムの状態が `Authorized` に変化した際に、割り当てた関数が実行されます。

SDK からの応答はカスタムイベントで処理できます。その際、Authentication SDK からの応答を表す [Authentication State Changed Response](./sdk-api/authentication/models/authentication-state-changed-response.md) を出力ピンとして受け取る必要があります。応答変数を分割するには、応答本文の出力ピンを右クリックして **Split Pin** を選択します。


**Register state changed callback:**
![Register state changed callback](/api/media?file=/authentication-unreal/media/images/unreal-auth-state-change-callback.png)

### Sign Out##sign-out

`Sign Out` を使用すると、現在認証されているプレイヤープロファイルからサインアウトできます。これにより、現在のプレイヤープロファイルが削除され、デフォルトのプロファイルに切り替わります。この関数には、プレイヤーに関連付けられた保存済みの認証情報を削除する、オプションのパラメーターもあります。

> **Note:**
>
> **ノート**: デフォルトプロファイルを使用しているときに `Sign Out` が呼び出されると、プロファイル情報が消去されますが、プロファイル自体は保持されます。

この関数は、操作が成功したかどうかを示す `Boolean` を返します。


**alt\_text:**
![alt\_text](/api/media?file=/authentication-unreal/media/images/unreal-auth-sign-out.png)

### Switch Profile##switch-profile

`Switch Profile` を使用すると、プレイヤープロファイルを切り替えたり、新しいプロファイルを作成したりできます。

> **Note:**
>
> **ノート**: `Switch Profile` は、サインアウト状態のときにのみ呼び出すことができます。認証された状態のときにプロファイルの切り替えが試みられた場合は、警告が記録され、何も実行されません。


**Switch profile:**
![Switch profile](/api/media?file=/authentication-unreal/media/images/unreal-auth-switch-profile.png)

### Profile Exists##profile-exists

`Profile Exists` を使用すると、指定したプロファイルが現在のセッションに存在するかどうかを確認できます。

> **Note:**
>
> **ノート**: 前のセッションで作成され、現在のセッションでは再作成されていないプロファイルがある場合、`Profile Exists` でそれらを検出することはできません。

この関数は、指定されたプロファイル名が現在のプレイヤープロファイルのリストに存在するかどうかを示す `Boolean` を返します。


**Profile exists:**
![Profile exists](/api/media?file=/authentication-unreal/media/images/unreal-auth-profile-exists.png)

### Get Current Profile Name##get-current-profile-name

`Get Current Profile Name` を使用すると、現在のプレイヤープロファイルの名前を取得できます。

この関数は、Authentication サブシステムが使用している現在のプレイヤープロファイルの名前を示す `String` を返します。


**Get current profile name:**
![Get current profile name](/api/media?file=/authentication-unreal/media/images/unreal-auth-current-name.png)

### Get Profile Names##get-profile-names

`Get Current Profile Names` を使用すると、現在のセッションで使用されているすべてのプレイヤープロファイル名のリストを取得できます。

この関数は、Authentication サブシステムで使用されているすべてのプレイヤープロファイル名を示す `String Array` を返します。


**Get profile names:**
![Get profile names](/api/media?file=/authentication-unreal/media/images/unreal-auth-profile-names.png)

### Register Profile Changed Callback##register-profile-changed-callback

`Register Profile Changed Callback` を使用すると、プレイヤープロファイルが変更されたときに呼び出されるコールバック関数を割り当てることができます。例えば、[Switch Profile](./blueprint-integration.md#switch-profile) が正常に実行されたときに、割り当てた関数が実行されます。

SDK からの応答はカスタムイベントで処理できます。その際、[Authentication Player Profile Changed Response](./sdk-api/authentication/models/authentication-player-profile-changed-response.md) を出力ピンとして受け取る必要があります。応答変数を分割するには、応答本文の出力ピンを右クリックして **Split Pin** を選択します。


**Register profile changed callback:**
![Register profile changed callback](/api/media?file=/authentication-unreal/media/images/unreal-auth-register-profile.png)

### Register Profile Deleted Callback##register-profile-deleted-callback

`Register Profile Changed Callback` を使用すると、プレイヤープロファイルが現在のセッションから削除されたときに呼び出されるコールバック関数を割り当てることができます。例えば、[Sign Out](./blueprint-integration.md#sign-out) が正常に実行されたときに、割り当てた関数が実行されます。

SDK からの応答はカスタムイベントで処理できます。その際、\[Authentication Player Profile] [Authentication Player Profile Deleted Response](./sdk-api/authentication/models/authentication-player-profile-deleted-response.md) を出力ピンとして受け取る必要があります。応答変数を分割するには、応答本文の出力ピンを右クリックして **Split Pin** を選択します。


**Register profile deleted callback:**
![Register profile deleted callback](/api/media?file=/authentication-unreal/media/images/unreal-auth-profile-deleted-callback.png)

### Is Signed In##is-signed-in

`Is Signed In` を使用すると、現在のプレイヤープロファイルがサインインしているかどうかを確認できます。"サインインしている" とは、Authorized (認証済み) または Expired (有効期限切れ) のいずれかの状態であることを意味します。

この関数は、現在のプレイヤープロファイルがサインインしているかどうかを示す `Boolean` を返します。


**Is signed in:**
![Is signed in](/api/media?file=/authentication-unreal/media/images/unreal-auth-signed-in.png)

### Is Anonymous##is-anonymous

`Is Anonymous` を使用すると、現在のプレイヤープロファイルが匿名でサインインしているかどうかを確認できます。`Sign In Anonymously` が正常に実行されると、true が返されます。

この関数は、現在のプレイヤープロファイルが匿名でサインインしているかどうかを示す `Boolean` を返します。最後のサインインが匿名であれば、セッションが期限切れであっても true が返されます。


**Is anonymous:**
![Is anonymous](/api/media?file=/authentication-unreal/media/images/unreal-auth-is-anonymous.png)

### Is Authorized##is-authorized

`Is Authorized` を使用すると、現在のプレイヤープロファイルがサインインしており、現在も認証されているかどうかを確認できます。

この関数は、現在のプレイヤープロファイルがサインインしており、認証に成功しているかどうかを示す `Boolean` を返します。サインイン関数が実行され、有効期限がまだ切れていなければ、true が返されます。


**Is authorized:**
![Is authorized](/api/media?file=/authentication-unreal/media/images/unreal-auth-is-authorized.png)

### Is Expired##is-expired

`Is Expired` を使用すると、現在の [プレイヤープロファイルの](./player-profiles.md) セッションが有効期限切れかどうかを確認できます。

この関数は、現在のプレイヤープロファイルのセッションが最初の [Authentication Response](./sdk-api/authentication/models/authentication-response.md) で返された有効期限を過ぎているかどうかを示す `Boolean` を返します。


**Is expired:**
![Is expired](/api/media?file=/authentication-unreal/media/images/unreal-auth-is-expired.png)

### Session Token Exists##session-token-exists

`Session Token Exists` を使用すると、現在のプレイヤープロファイルのプレイヤー設定に [セッショントークン](./sdk-api/authentication/models/authentication-response.md#sessiontoken) が存在するかどうかを確認できます。

この関数は、セッショントークンが存在するかどうかを示す `Boolean` を返します。


**Session tokene exists:**
![Session tokene exists](/api/media?file=/authentication-unreal/media/images/unreal-auth-token-exists.png)

### Get Unity Project Id##get-unity-project-id

`Get Unity Project Id` を使用すると、現在の認証セッションに関連付けられている Unity プロジェクト ID を取得できます。

この関数は、現在使用中のプロジェクト ID を示す `Guid` を返します。


**Get Unity project ID:**
![Get Unity project ID](/api/media?file=/authentication-unreal/media/images/unreal-auth-get-unity-project.png)

### Get Unity Environment Name##get-unity-environment-name

`Get Unity Environment Name` を使用すると、現在の認証セッションに関連付けられている Unity 環境名を取得できます。

この関数は、現在使用中の環境を示す `String` を返します。


**Get Unity Environment Name:**
![Get Unity Environment Name](/api/media?file=/authentication-unreal/media/images/unreal-auth-get-env-name.png)

### Get Access Token##get-access-token

`Get Access Token` を使用すると、現在のセッションの [アクセストークン](./sdk-api/authentication/models/authentication-response.md) を取得できます。当該の文字列が存在しない場合は、空の文字列が返されます。


**Get access token:**
![Get access token](/api/media?file=/authentication-unreal/media/images/unreal-auth-get-access-token.png)

### Get Session Token##get-session-token

`Get Session Token` を使用すると、現在のセッションの [セッショントークン](./sdk-api/authentication/models/authentication-response.md) を取得できます。当該の文字列が存在しない場合は、空の文字列が返されます。


**Get session token:**
![Get session token](/api/media?file=/authentication-unreal/media/images/unreal-auth-get-session-token.png)

### Get User Id##get-user-id

`Get User Id` 関数を使用すると、現在のセッションの [ユーザー ID](./sdk-api/authentication/models/authentication-response.md#userid) を取得できます。

> **Note:**
>
> **ノート**: これは [プレイヤープロファイル名](./blueprint-integration.md#get-current-profile-name) とは異なります。ユーザー ID は、Unity Authentication System から返される一意のユーザー識別子です。

この関数は、現在のプレイヤープロファイルのユーザー ID を示す `String` を返します。当該の文字列が存在しない場合は、空の文字列が返されます。


**Get user ID:**
![Get user ID](/api/media?file=/authentication-unreal/media/images/unreal-auth-get-user-id.png)

### Get State##get-state

`Get State` 関数を使用すると、認証セッションの現在の [状態](./sdk-api/authentication/authentication-states.md) を取得できます。

この関数は、サブシステムの状態を表す `Enum` を返します。


**Get state:**
![Get state](/api/media?file=/authentication-unreal/media/images/unreal-auth-get-state.png)

### Set Unity Project Id##set-unity-project-id

`Set Unity Project Id` を使用すると、現在の認証セッションに対して [Unity プロジェクト ID](./get-started.md#link-your-project) を設定できます。この関数は `Guid` を受け取ります。

> **Note:**
>
> **ノート**: これが実行されると、プロジェクト設定で設定された Unity プロジェクト ID がオーバーライドされます。


**Set Unity project ID:**
![Set Unity project ID](/api/media?file=/authentication-unreal/media/images/unreal-auth-unity-project-id.png)

### Set Unity Environment Name##set-unity-environment-name

`Set Unity Environment Name` を使用すると、現在の認証セッションに対して [Unity 環境名](./get-started.md#link-your-project) を設定できます。この関数は `String` を受け取ります。

> **Note:**
>
> **ノート**: これが実行されると、プロジェクト設定で設定された Unity 環境名がオーバーライドされます。


**Set Unity Environment Name:**
![Set Unity Environment Name](/api/media?file=/authentication-unreal/media/images/unreal-auth-set-env-name.png)
