Playmaker Forum

Bug Reporting => PlayMaker Bug Reporting => Topic started by: doppelmonster on March 17, 2015, 12:03:16 AM

Title: "Set Parent" throws warnings since Unity5
Post by: doppelmonster on March 17, 2015, 12:03:16 AM
Hi,

since Unity5 i get a warning when using the "set parent" action which clutters my console:

Code: [Select]
Parent of RectTransform is being set with parent property. Consider using the SetParent method instead, with the worldPositionStays argument set to false. This will retain local orientation and scale rather than world orientation and scale, which can prevent common UI scaling issues.
UnityEngine.Transform:set_parent(Transform)
HutongGames.PlayMaker.Actions.SetParent:OnEnter() (at Assets/PlayMaker/Actions/SetParent.cs:38)
HutongGames.PlayMaker.FsmState:ActivateActions(Int32)
HutongGames.PlayMaker.FsmState:OnEnter()
HutongGames.PlayMaker.Fsm:EnterState(FsmState)
HutongGames.PlayMaker.Fsm:SwitchState(FsmState)
HutongGames.PlayMaker.Fsm:UpdateStateChanges()
HutongGames.PlayMaker.Fsm:DoTransition(FsmTransition, Boolean)
HutongGames.PlayMaker.Fsm:ProcessEvent(FsmEvent, FsmEventData)
HutongGames.PlayMaker.Fsm:Event(FsmEventTarget, FsmEvent)
HutongGames.PlayMaker.Fsm:Event(FsmEvent)
HutongGames.PlayMaker.Fsm:Event(String)
PlayMakerFSM:SendEvent(String)
UnityEngine.EventSystems.EventSystem:Update()

http://docs.unity3d.com/ScriptReference/Transform.SetParent.html (http://docs.unity3d.com/ScriptReference/Transform.SetParent.html)

I am not sure how to fix this action myself but it shouldnt be to difficult.
Title: Re: "Set Parent" throws warnings since Unity5
Post by: doppelmonster on March 17, 2015, 12:24:00 AM
I fixed it myself. would be nice if you could check it and incorporate it in the next update.

Code: [Select]
// (c) Copyright HutongGames, LLC 2010-2013. All rights reserved.

using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.GameObject)]
[Tooltip("Sets the Parent of a Game Object.")]
public class SetParent : FsmStateAction
{
[RequiredField]
[Tooltip("The Game Object to parent.")]
public FsmOwnerDefault gameObject;

[Tooltip("The new parent for the Game Object.")]
public FsmGameObject parent;

[Tooltip("Set the local position to 0,0,0 after parenting.")]
public FsmBool resetLocalPosition;

[Tooltip("Set the local rotation to 0,0,0 after parenting.")]
public FsmBool resetLocalRotation;

public override void Reset()
{
gameObject = null;
parent = null;
resetLocalPosition = null;
resetLocalRotation = null;
}

public override void OnEnter()
{
var go = Fsm.GetOwnerDefaultTarget(gameObject);

if (go != null)
{
if (parent.Value != null)
{
go.transform.SetParent(parent.Value.transform,true);
// old syntax:
//go.transform.parent = parent.Value == null ? null : parent.Value.transform;

if (resetLocalPosition.Value)
{
go.transform.localPosition = Vector3.zero;
}

if (resetLocalRotation.Value)
{
go.transform.localRotation = Quaternion.identity;
}
}
}

Finish();
}
}
}
Title: Re: "Set Parent" throws warnings since Unity5
Post by: jeanfabre on March 17, 2015, 01:03:04 AM
Hi,

 Uhm, I think we have a special case to deal with with RecTransform, you are trying to set the parent of a UI element, which will act differently and behave differently based on the layout setup around that ui element and this new parent.

 I think we should instead have a special action targeted for RecTransform. Let me work on this.

 Bye,

 Jean
Title: Re: "Set Parent" throws warnings since Unity5
Post by: doppelmonster on March 17, 2015, 01:36:54 AM
yes you are right, the error is only thrown by GUI objects.

Thanks for taking care of it!

Title: Re: "Set Parent" throws warnings since Unity5
Post by: jeanfabre on March 18, 2015, 01:17:36 AM
Hi,

 ok, I created a new action to deal with this new function ( the setparent action was doing this manually actually).

You can get it on the Ecosystem (https://hutonggames.fogbugz.com/default.asp?W1181).

It's actually something introduce in late 4.x releases, so it's not just for u5.

 Bye,

 Jean
Title: Re: "Set Parent" throws warnings since Unity5
Post by: terri on June 26, 2015, 09:33:10 AM
what's this new action called?
I tried searching for parent and rectransform and nothing came up

edit: nevermind, found it ( set transform parent )
Title: Re: "Set Parent" throws warnings since Unity5
Post by: Alatriste on June 25, 2017, 02:08:48 AM
Thanks! I couldn't find it!
Now all warnings are gone! :)