2D Toolkit Forum

2D Toolkit => Support => Topic started by: Xaron on September 06, 2016, 09:24:25 am

Title: Prefab with camera anchor loses the public camera variable
Post by: Xaron on September 06, 2016, 09:24:25 am
Dear all,

I have a strange problem with a prefab. It's a tk2d text prefab which has a tk2dcameraanchor attached to it. This anchor has a public variable called "Camera". Everytime I restart Unity (5.4) this prefab loses the camera variable. Is there a solution to that?

Please take a look at the attached screenshots. Thanks!
Title: Re: Prefab with camera anchor loses the public camera variable
Post by: unikronsoftware on September 11, 2016, 12:20:36 pm
Hi there,

Where is this variable? Is it in the scene?
The asset is in the project folder, so it won't be able to retain a link to anything that is in the scene...
Title: Re: Prefab with camera anchor loses the public camera variable
Post by: Xaron on September 12, 2016, 08:34:25 am
Hi,

yes it's in the scene. Hmm I see.

I just add inside the Start() method now:
Code: [Select]
    _tk2dCamera = GameObject.Find( "tk2dCamera" ).GetComponent<Camera>();
    _textAnchor.transform.parent = _tk2dCamera.transform;
    _textAnchor.AnchorCamera = _tk2dCamera;

Thanks!
Title: Re: Prefab with camera anchor loses the public camera variable
Post by: kgilbert2 on September 15, 2016, 05:12:38 pm
Am I wrong that you can call tk2dCamera.Instance in code to get a reference to your camera?

Code: [Select]
  _tk2dCamera = tk2dCamera.Instance;
    _textAnchor.transform.parent = _tk2dCamera.transform;
    _textAnchor.AnchorCamera = _tk2dCamera;
Title: Re: Prefab with camera anchor loses the public camera variable
Post by: unikronsoftware on September 21, 2016, 02:33:22 pm
That should work fine as long as you're not using viewport clipping.