Forum rules - please read before posting.

How to set a Global Variable of type GameObject via script?

I want to set a GameObject as a global variable via script, in order to use it in another scene. I have created the variable from the Variables menu in the Editor, but the AC.GlobalVariables class has set methods only for Boolean, Float etc, not for GameObject. Am I missing something?

Comments

  • I eventually figured out a way:

    AC.GlobalVariables.GetVariable("varname").GameObjectValue = myGameObject;

    I don't know if it's optimal, but it works...

  • Yes, that's it.

    You can optimise it by storing a reference to the variable, but it'd be a minimal difference unless you're setting it every frame:

    AC.GVar myVariable = AC.GlobalVariables.GetVariable("varname");
    myVariable.GameObjectValue = myGameObject;
    
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.