<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Unity basic setup]]></title><description><![CDATA[<p dir="auto">Hello,</p>
<p dir="auto">Unity noob here, trying to understand how to properly use Braincloud in Unity for different scenes. So far i've attached the following script in an empty GameObject and it succesfully passes through scenes.</p>
<pre><code>public class BCConfig : MonoBehaviour
{
    private BrainCloudWrapper _bc;

    public BrainCloudWrapper GetBrainCloud()
    {
        return _bc;
    }

    void Awake()
    {
        DontDestroyOnLoad(this.gameObject);
        _bc = this.gameObject.AddComponent&lt;BrainCloudWrapper&gt;();

        _bc.WrapperName = gameObject.name;    // Optional: Set a wrapper name
        _bc.Init();      // Init data is taken from the brainCloud Unity Plugin   
    }

}
</code></pre>
<p dir="auto">Now in a different scene, in the start() function i use this: _bc = BCConfig.GetBrainCloud(); but i get an error (Object reference not set to an instance of an object).</p>
<p dir="auto">What am i missing here? Would using a static BraincloudWrapper work aswell?</p>
]]></description><link>https://forums.getbraincloud.com/topic/44/unity-basic-setup</link><generator>RSS for Node</generator><lastBuildDate>Tue, 21 Apr 2026 10:19:58 GMT</lastBuildDate><atom:link href="https://forums.getbraincloud.com/topic/44.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 13 Sep 2019 12:55:25 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Unity basic setup on Fri, 13 Sep 2019 20:02:52 GMT]]></title><description><![CDATA[<p dir="auto">Yes, that solved the problem.  Thanks for your input Chris. Although, i'm always "scared" of using statics so i ended up doing it in a kindly different way.</p>
<p dir="auto">Since the forum is new, i'll post the solution here in case any future newbies like myself get stuck in the same problem. It's more of a Unity problem and less of a BrainCloud problem but thanks to BC support, i understood what i was doing wrong.</p>
<p dir="auto">In order to use BrainCloud in multiple scenes you can either use a static variable like Chris said (it's easier doing it like that) or you need to create a GameObject and attach to it the script below.</p>
<pre><code>using UnityEngine;

public class BCConfig : MonoBehaviour
{
    private BrainCloudWrapper _bc;

    public BrainCloudWrapper GetBrainCloud()
    {
        return _bc;
    }

    void Awake()
    {
        
        gameObject.name = "BrainCloud"; // I assign the name Braincloud to my game object to use it in the Find() function
        _bc = gameObject.AddComponent&lt;BrainCloudWrapper&gt;();
        _bc.WrapperName = "MyWrapper"; // optionally set a wrapper-name
        _bc.Init(); // extra data, such as: _appId, _secret and _appVersion, is taken from the brainCloud Unity Plugin. See Installation Guide above
        DontDestroyOnLoad(gameObject);
    }

}

</code></pre>
<p dir="auto">In some other scene where you need access to the _bc variable you just simply do the following on the start method:</p>
<pre><code> _bc = GameObject.Find("BrainCloud").GetComponent&lt;BCConfig&gt;().GetBrainCloud();
</code></pre>
<p dir="auto">edit: small fix made to the example code, by a brainCloud mod (<a class="plugin-mentions-user plugin-mentions-a" href="https://forums.getbraincloud.com/uid/6">@Jonathan</a>)</p>
]]></description><link>https://forums.getbraincloud.com/post/162</link><guid isPermaLink="true">https://forums.getbraincloud.com/post/162</guid><dc:creator><![CDATA[Panagiotis Milios]]></dc:creator><pubDate>Fri, 13 Sep 2019 20:02:52 GMT</pubDate></item><item><title><![CDATA[Reply to Unity basic setup on Fri, 13 Sep 2019 19:38:00 GMT]]></title><description><![CDATA[<p dir="auto">Cool to see the forums working! <img src="https://forums.getbraincloud.com/assets/plugins/nodebb-plugin-emoji/emoji/android/1f642.png?v=97ramm8ajhq" class="not-responsive emoji emoji-android emoji--slightly_smiling_face" style="height:23px;width:auto;vertical-align:middle" title=":)" alt="🙂" /></p>
<p dir="auto">I've marked <a class="plugin-mentions-user plugin-mentions-a" href="https://forums.getbraincloud.com/uid/48">@Panagiotis-Milios</a>  more detailed explanation as the accepted solution, but kudos to you <a class="plugin-mentions-user plugin-mentions-a" href="https://forums.getbraincloud.com/uid/22">@Chris-Brown</a> for pointing it out, and <a class="plugin-mentions-user plugin-mentions-a" href="https://forums.getbraincloud.com/uid/48">@Panagiotis-Milios</a> for providing the detailed example. Thanks a bunch! <img src="https://forums.getbraincloud.com/assets/plugins/nodebb-plugin-emoji/emoji/android/1f642.png?v=97ramm8ajhq" class="not-responsive emoji emoji-android emoji--slightly_smiling_face" style="height:23px;width:auto;vertical-align:middle" title=":)" alt="🙂" /></p>
]]></description><link>https://forums.getbraincloud.com/post/164</link><guid isPermaLink="true">https://forums.getbraincloud.com/post/164</guid><dc:creator><![CDATA[Paul Winterhalder]]></dc:creator><pubDate>Fri, 13 Sep 2019 19:38:00 GMT</pubDate></item><item><title><![CDATA[Reply to Unity basic setup on Fri, 13 Sep 2019 19:35:51 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://forums.getbraincloud.com/uid/48">@Panagiotis-Milios</a></p>
<p dir="auto">Nothing wrong with using Static, just have to know when to use it and when not to.<br />
I avoid GameObject.Find, but some are ok with it at the start of a scene.</p>
<p dir="auto">Glad you have a solution that works for you.</p>
]]></description><link>https://forums.getbraincloud.com/post/163</link><guid isPermaLink="true">https://forums.getbraincloud.com/post/163</guid><dc:creator><![CDATA[Chris Brown]]></dc:creator><pubDate>Fri, 13 Sep 2019 19:35:51 GMT</pubDate></item><item><title><![CDATA[Reply to Unity basic setup on Fri, 13 Sep 2019 20:02:52 GMT]]></title><description><![CDATA[<p dir="auto">Yes, that solved the problem.  Thanks for your input Chris. Although, i'm always "scared" of using statics so i ended up doing it in a kindly different way.</p>
<p dir="auto">Since the forum is new, i'll post the solution here in case any future newbies like myself get stuck in the same problem. It's more of a Unity problem and less of a BrainCloud problem but thanks to BC support, i understood what i was doing wrong.</p>
<p dir="auto">In order to use BrainCloud in multiple scenes you can either use a static variable like Chris said (it's easier doing it like that) or you need to create a GameObject and attach to it the script below.</p>
<pre><code>using UnityEngine;

public class BCConfig : MonoBehaviour
{
    private BrainCloudWrapper _bc;

    public BrainCloudWrapper GetBrainCloud()
    {
        return _bc;
    }

    void Awake()
    {
        
        gameObject.name = "BrainCloud"; // I assign the name Braincloud to my game object to use it in the Find() function
        _bc = gameObject.AddComponent&lt;BrainCloudWrapper&gt;();
        _bc.WrapperName = "MyWrapper"; // optionally set a wrapper-name
        _bc.Init(); // extra data, such as: _appId, _secret and _appVersion, is taken from the brainCloud Unity Plugin. See Installation Guide above
        DontDestroyOnLoad(gameObject);
    }

}

</code></pre>
<p dir="auto">In some other scene where you need access to the _bc variable you just simply do the following on the start method:</p>
<pre><code> _bc = GameObject.Find("BrainCloud").GetComponent&lt;BCConfig&gt;().GetBrainCloud();
</code></pre>
<p dir="auto">edit: small fix made to the example code, by a brainCloud mod (<a class="plugin-mentions-user plugin-mentions-a" href="https://forums.getbraincloud.com/uid/6">@Jonathan</a>)</p>
]]></description><link>https://forums.getbraincloud.com/post/162</link><guid isPermaLink="true">https://forums.getbraincloud.com/post/162</guid><dc:creator><![CDATA[Panagiotis Milios]]></dc:creator><pubDate>Fri, 13 Sep 2019 20:02:52 GMT</pubDate></item><item><title><![CDATA[Reply to Unity basic setup on Fri, 13 Sep 2019 18:45:40 GMT]]></title><description><![CDATA[<p dir="auto">GetBrainCloud() isn't static, which means in your other script what is BCConfig? Looks like you're missing a reference to it from what I can see.  Even though your GameObject may carry over, you'll still need a reference to it.</p>
<p dir="auto">As you mentioned, making the variable static would work. I use this in our apps, and just assign the value in awake.</p>
<p dir="auto">public static BrainCloudWrapper brainCloudWrapper;</p>
<p dir="auto">Then in your case, you'd just reference it with BCConfig._bc; (using your variable name)</p>
]]></description><link>https://forums.getbraincloud.com/post/159</link><guid isPermaLink="true">https://forums.getbraincloud.com/post/159</guid><dc:creator><![CDATA[Chris Brown]]></dc:creator><pubDate>Fri, 13 Sep 2019 18:45:40 GMT</pubDate></item></channel></rss>