playMaker

Author Topic: [SOLVED] UGUI text prefab position problem.  (Read 1473 times)

NathanParable

  • Playmaker Newbie
  • *
  • Posts: 6
[SOLVED] UGUI text prefab position problem.
« on: September 06, 2016, 06:51:09 PM »
So, I have a GameObject which is some ugui text. It was created in a canvas, anchored to the lower left corner, pivot set to 0,0, and position set to 50,20. I then attached an FSM that gives it some basic fade-in/fade-out animation, and saved the GameObject as a prefab.

The idea is that i'll spawn this prefab whenever I need some dialogue, using the ugui Set Text action to change what's being said. The spawning is done by using a Create Object action (using the Canvas as a spawn point) and then using Set Parent to attach it to the canvas.

For the most part it works fine, but for the life of me I can't get the positioning right.

I've tried using a combination of Set Position, Rect Transform Set Local Position, and even Rect Transform Screen Point To Local Point In Rectangle, but I never get the positioning spot on, it's either a bit off or way off. Heck, Rect Transform Set Local Position didn't seem to make any difference at all.

I guess the skinny of it is; how do I spawn a prefab UI element into a ugui canvas with the correct positioning?
« Last Edit: September 06, 2016, 09:15:11 PM by TheNathanParable »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: UGUI text prefab position problem.
« Reply #1 on: September 06, 2016, 08:35:08 PM »
Hi,
Maybe instead of using a prefab you could enable/disable the object.
you can use the "ActivateGameObject" action for this.
create and destroy are 'expensive' ('read lag' when using several in a single frame)

NathanParable

  • Playmaker Newbie
  • *
  • Posts: 6
Re: UGUI text prefab position problem.
« Reply #2 on: September 06, 2016, 09:14:39 PM »
That's...a very good point. I'm not sure why I thought I needed to constantly create/destroy the same object when I could just activate/deactivate the visibility of said object.

After some tinkering...yeah, that method seems to work much better.

Thanks for the help. :)