Hello Guest

Author Topic: Prefab with camera anchor loses the public camera variable  (Read 5520 times)

Xaron

  • Newbie
  • *
  • Posts: 3
    • View Profile
Prefab with camera anchor loses the public camera variable
« 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!

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Prefab with camera anchor loses the public camera variable
« Reply #1 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...

Xaron

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Prefab with camera anchor loses the public camera variable
« Reply #2 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!

kgilbert2

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Prefab with camera anchor loses the public camera variable
« Reply #3 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;

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Prefab with camera anchor loses the public camera variable
« Reply #4 on: September 21, 2016, 02:33:22 pm »
That should work fine as long as you're not using viewport clipping.