0

I have a Unity WebGL app that is using the AssetBundle Manager to load a prefab. It's successfully loading the prefab and associated animations, but I can't reference the script attached to the prefab. I'm not trying to include the script in the asset bundle - it's in the base application. I have code stripping disabled.

What's really confusing me is that my code able to reference it while running in the editor, but not when it's running in the browser.

My prefab is structured like this:

  • Container GameObject
    • 3D Text

MyScript is defined like this:

public class MyScript : MonoBehaviour {
  public TextMesh Text;
}

My code where I try to access the script:

var container = Instantiate (prefab);
var script = container.GetComponent<MyScript> ();

The Container GameObject has a script component. The script references the 3D Text via a public property. When the prefab is instantiated while in the browser, the 3D Text object renders correctly, but script is null.

Is there something I'm doing wrong, or is it just not possible to do this in the WebGL player?

Dave Cowart
  • 781
  • 6
  • 17
  • 1
    *"but animationTemplate is null."* What is `animationTemplate` and what does that have to do with the code in your question? Note that you have actually not mentioned what's wrong with your code. – Programmer Jul 25 '17 at 23:11
  • @Programmer sorry, I'd renamed variables to make it easier to read, and missed that one. `script` is null, but only when the game is running in the browser. It is not null when running in the editor. – Dave Cowart Jul 26 '17 at 15:39
  • Two questions: 1.Is the `MyScript` attached to the prefab? 2.How is the `prefab` variable initialized? If this is done from the Editor, where/what folder did you put that prefab? – Programmer Jul 26 '17 at 23:19

0 Answers0