playMaker

Author Topic: "Set Parent" throws warnings since Unity5  (Read 14960 times)

doppelmonster

  • Full Member
  • ***
  • Posts: 157
    • Grinder Games
"Set Parent" throws warnings since Unity5
« on: March 17, 2015, 03: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

I am not sure how to fix this action myself but it shouldnt be to difficult.

doppelmonster

  • Full Member
  • ***
  • Posts: 157
    • Grinder Games
Re: "Set Parent" throws warnings since Unity5
« Reply #1 on: March 17, 2015, 03: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();
}
}
}

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: "Set Parent" throws warnings since Unity5
« Reply #2 on: March 17, 2015, 04: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

doppelmonster

  • Full Member
  • ***
  • Posts: 157
    • Grinder Games
Re: "Set Parent" throws warnings since Unity5
« Reply #3 on: March 17, 2015, 04:36:54 AM »
yes you are right, the error is only thrown by GUI objects.

Thanks for taking care of it!


jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: "Set Parent" throws warnings since Unity5
« Reply #4 on: March 18, 2015, 04: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.

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

 Bye,

 Jean

terri

  • Sr. Member
  • ****
  • Posts: 386
    • terrivellmann.tumblr.com
Re: "Set Parent" throws warnings since Unity5
« Reply #5 on: June 26, 2015, 12:33:10 PM »
what's this new action called?
I tried searching for parent and rectransform and nothing came up

edit: nevermind, found it ( set transform parent )
« Last Edit: June 26, 2015, 12:36:08 PM by terri »

Alatriste

  • Full Member
  • ***
  • Posts: 193
Re: "Set Parent" throws warnings since Unity5
« Reply #6 on: June 25, 2017, 05:08:48 AM »
Thanks! I couldn't find it!
Now all warnings are gone! :)