Setup & Initialize: wire it into the client
Authentication is what runs right after this succeeds; every call in that article, and everywhere else in this series, assumes Init() already ran.
- Initialize (C++, Java, JavaScript, Dart, C# (.NET), C# (Unity), GDScript (Godot), Unreal C++)
This needs to be done first, before anything else: every other call in this series assumes it already succeeded.
Nothing in this series works without two things happening first, in order: an app has to exist in the brainCloud portal (that's where an appId and secret come from), and the client has to be told about it, by name, before it makes a single other call. That second step is Init() (Unity/C#/C++) or initialize() (the equivalent on every other SDK): it configures the BrainCloudClient, points it at a server URL, and hands it the appId/secret/version that identify which app it's talking to. Authenticate, RunScript, every service call in this series, all assume Init() already succeeded; none of them work before it.
How it works
- An app has to exist in the portal before any client code runs. Every environment (dev, prod) is its own app row in the brainCloud portal, each with its own appId and secret. Nothing else in this series is possible until one exists.
- The client's Init() call is the hand-off: it has to run, successfully, before anything else. It takes a server URL, secret, appId, and version, builds the underlying BrainCloudClient, and is a hard prerequisite: CanReconnect(), AuthenticateAnonymous, AuthenticateEmailPassword, RunScript, every service call in every later article, all assume Init() already succeeded.
- Every other SDK takes those same four values explicitly, by hand, copied out of the portal. The call and argument order differ per platform (see the Initialize entry in the apps list above for each SDK's actual definition): C++ takes (serverURL, secretKey, appId, appVersion), JavaScript takes (appId, secret, appVersion, serverUrl) instead, Unreal matches C++'s order, and Java, Dart, and GDScript each have their own ordering again; there's no portal integration on the client side for any of them.
- Unity's Editor plugin removes the copy-paste step. Its OAuth login (PKCE, no manual API key pasted anywhere) authenticates the developer against the portal directly from inside the Unity Editor, then lets them fetch the list of apps on their team, create a new one, or create one from a template/example project, all without ever seeing a raw secret. The result is written into the project's BrainCloudSettings asset.
- Unity's runtime Init() call takes zero arguments, and reads from that same settings asset. Instead of Init(url, secret, appId, version), a Unity project calls the parameterless Wrapper.Init(), which pulls all four values from BrainCloud.Plugin.Interface, the same object the Editor plugin populated. No credential ever needs to appear in source.
- This has to be the first brainCloud call a Unity app makes. Marketplace calls it in its top-level manager's Awake(), before anything else, and checks Client.Initialized right after, the same pattern Authentication then builds a reconnect-or-login gate on top of.
Code
private void Awake()
{
//...
// Initialize BrainCloud wrapper
BCWrapper = GetComponent<BrainCloudWrapper>();
BCWrapper.Init();
BCWrapper.EnableAutoReconnect(true);
Debug.Log("BCManager initialized and BrainCloudWrapper ready.");
isInitialized = BCWrapper.Client.Initialized;
OnBrainCloudInitialized?.Invoke();
}public void Init()
{
resetWrapper();
Init(
BrainCloud.Plugin.Interface.DispatcherURL,
BrainCloud.Plugin.Interface.AppSecret,
BrainCloud.Plugin.Interface.AppId,
BrainCloud.Plugin.Interface.AppVersion);
Client.EnableLogging(BrainCloud.Plugin.Interface.EnableLogging);
}Gotchas worth knowing up front
- Init() and Init(url, secretKey, appId, version) are not interchangeable inside the same Unity project. The zero-arg overload only has values to read once the Editor plugin has populated them; calling it before that's done points the client at nothing.