Forum rules - please read before posting.

Error when parenting a UI prefab (World Space) to Draggables in different scenes

Hey Chris,

I have a Unity UI Prefab – a score counter, actually – that lives in world space and is supposed to show up in different scenes as part of the setting (and thus is added by AC at runtime to these scenes). As the counter sits on a draggable object, I have to set this draggable as the counter's parent in an action list after the scene has started – but Unity advises me not to:

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)
AC.ActionParent:Run() (at Assets/AdventureCreator/Scripts/Actions/ActionParent.cs:71)
AC.<RunAction>c__Iterator2:MoveNext() (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:347)
UnityEngine.MonoBehaviour:StartCoroutine(String, Object)
AC.ActionList:ProcessAction(Int32) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:306)
AC.ActionList:ProcessActionEnd(ActionEnd, Int32, Boolean) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:520)
AC.ActionList:EndAction(Action) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:438)
AC.<RunAction>c__Iterator2:MoveNext() (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:407)

Still the parenting works … until I change scenes; then this error comes up:

-> AC debug logger
UnityEngine.Debug:Log(Object, Object)
AC.ACDebug:Log(Object, Object) (at Assets/AdventureCreator/Scripts/Static/ACDebug.cs:16)
AC.SaveFileHandler_SystemFile:Save(SaveFile, String) (at Assets/AdventureCreator/Scripts/Save system/FileHandling/SaveFileHandler_SystemFile.cs:95)
AC.<PrepareSaveCoroutine>c__Iterator0:MoveNext() (at Assets/AdventureCreator/Scripts/Save system/SaveSystem.cs:865)
UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
AC.SaveSystem:SaveSaveGame(Int32, Boolean, String) (at Assets/AdventureCreator/Scripts/Save system/SaveSystem.cs:815)
AC.SaveSystem:SaveAutoSave() (at Assets/AdventureCreator/Scripts/Save system/SaveSystem.cs:670)
AC.ActionListManager:PurgeLists() (at Assets/AdventureCreator/Scripts/Managers/ActionListManager.cs:662)
AC.ActionListManager:SetCorrectGameStateEnd() (at Assets/AdventureCreator/Scripts/Managers/ActionListManager.cs:628)
AC.ActionListManager:EndList(ActiveList) (at Assets/AdventureCreator/Scripts/Managers/ActionListManager.cs:541)
AC.ActionListManager:EndList(ActionList) (at Assets/AdventureCreator/Scripts/Managers/ActionListManager.cs:508)
AC.ActionList:Kill() (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:624)
AC.<EndCutscene>c__Iterator3:MoveNext() (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:553)

I have no idea what all of this means, because I am no pro coder. Am I doing something I shouldn't do?

Best, Jens

Comments

  • I forgot to post this part of the message:

    Setting the parent of a transform which resides in a prefab is disabled to prevent data corruption.

    UnityEngine.Transform:set_parent(Transform)
    AC.ActionParent:Run() (at Assets/AdventureCreator/Scripts/Actions/ActionParent.cs:71)
    AC.<RunAction>c__Iterator2:MoveNext() (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:347)
    UnityEngine.MonoBehaviour:StartCoroutine(String, Object)
    AC.ActionList:ProcessAction(Int32) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:306)
    AC.ActionList:ProcessActionEnd(ActionEnd, Int32, Boolean) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:520)
    AC.ActionList:EndAction(Action) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:438)
    AC.<RunAction>c__Iterator2:MoveNext() (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:407)
  • edited August 2018
    Essentially I think, I just would have to prevent the prefab from being added at runtime by putting it into each scene as a child to the Draggable beforehand (with the same Constant ID in each scene) like it works with a First Person Player prefab, but when I try this, the prefab gets added anyway so that I have two scoremeters in the scene.
  • If your Menu's Source is Unity Ui Prefab, the Canvas prefab will be spawned in at runtime automatically.  As this is set to survive scene changes, it needs to be left alone in the Hierarchy.

    What you want instead is Unity Ui In Scene, which requires an instance of your Canvas to be present in each scene you want access to it.  The Menu Manager will find it and connect up to it automatically when the scene begins, but won't spawn anything in.
  • Thanks, Chris – I got this to work as you predicted! :-)
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.
Do NOT follow this link or you will be banned from the site!