Forum rules - please read before posting.

Having problems AC linked UI prefabs - getting written on runtime

edited August 14 in Technical Q&A

Since I updated Unity to 2022.3.9f1 and AC to 1.81.5 I'm having problems with some graphic elements of my older menus correctly working. AC "say" its lose connection with the images, because for some reason, the prefabs are modified and some game objects hidden (Basically, when an asset actionlist tells the engine to hide a menu, the element remains hidden in the prefab and AC Is no longer able to find the linked graphic next time I play the game in the editor.

Worst than that, sometimes, I get in the console that can't find the linked UI image, but even then, the actionlist code works and shows or hide the element correctly. Other times, don't. Also, the assigned graphics on the prefab get blanked (set to none) after executing AC, so AC is rewriting the prefabs on runtime, not the prefab instances.

I even got to the point to deleting the elements on the menu, creating new ones, reassigning them, to no avail.

In fact, When I select in the unity editor a graphic element inside the prefab that previously worked, next time I run the game on the editor, AC menu loses the connection to that element, when before selecting it, it worked. So looks like some bug between AC and Unity prefabs. This happens for every graphic element that I select in the unity editor that is linked to AC. (Constant IDs and all that is fine, not modified).

Is a hell of a kerfuffle, I should have to sent dozens and dozens of pics about the menu settings and what happens after I do what to show the results, or a video, so It will be good if I'm told where I should focus to look to try to show exactly what's the problem beyond the explanation.

Maybe it's only a Unity problem about saving prefabs on runtime?? No idea.
Or I just missed some explanation about how this to not happen in the last years of AC updates.

PS: Same behaviour in Build

Comments

  • The Image's GameObject in the Hierarchy will need to be enabled on startup for it to be found. It can be disabled at runtime from then on.

    How is it that the original prefab is being affected? Are you relying on a custom script? It's important to only affect the "live" Menu at runtime, as opposed to the original - if so, share the script and I'll see what needs amending.

    Otherwise, share screenshots of the Actions involved that appear to be affecting the original Menu prefab.

  • You sort of give me the clue to solve it when talking about custom script...

    In both the menus I had problems, I'm was using "Custom Script" in some Toggle elements, but I don't really use any custom script. It was a way to avoid using AC to toggle directly the variable, and only toggling the variable I use to control the information show when the toggle buttons were shown (in order to use Unity Engine Toggle group. This worked well this the 3 years old AC version I was previously using.

    After updating, I saw it was giving some problems, and modified and fiddled a bit with the Toggle Group parameters, changed a bit the actionlists about when to check the variables to show hide elements, and it was working again.

    But I guess it was then I noticed the strange console logs about graphic elements unlinking (graphic elements unrelated to anything with the toggles AC logic). And prefabs behaving strange reseting the graphics of the graphic elements that didn't even had any logic part on the toggles.

    I had to change to regular use of variables, reassign the graphic elements, and restart Unity in order to have the problem solved.

    Was the restart unity the biggest problem to know if the changes I was making were solving anything.

    So I see, I just need to change the logic of how the toggle works and never relay on "custom script" option if there are no custom scripts on the logic (It worked before so...). Well, Now I know. Thank you!

    Just unlucky that AC doesn't handle toggle groups. I guess I'll just add some extra variables to handle the diverse toggle options.

  • Setting the Toggle to Custom Script shouldn't have an adverse effect - it should just prevent its value from being automatically set. It doesn't affect its visibility / enabled state. There may be another factor at play if that's the behaviour you're seeing.

  • Strangely enough, that was the only ocurrences of problem and the fix I followed worked straight for both menus.
    As console warnings weren't more specific and the situation so confusing, I cannot pinpoint the origin of the error.

  • As you said, it has nothing to do with custom scripts, but my use of having graphic menu elements not visible at start was the key problem. The problem is 100% reproducible on my build, I made several tests using a menu that only uses graphic elements that are shown or hidden with actionlist logic. (Is a quest tracker that I made, before you added Objectives to the game)

    -With AC Editor no visible, open a Menu prefab with graphic elements that worked without problems previously.
    -Duplicate a graphic element that is attached to AC menu (any).
    -Delete the automatically constant ID created (just in case).
    -Go to AC menu editor. Duplicate an image graphic component (visible on start: disabled)
    -Assign the new image graphic component (keeping it as disabled)

    -Check on editor Play:
    -Open the menu. Now, Console says that the UI.Image linked cannot be found, not for the new component, the duplicated AC menu graphic component (not the ui image duplicated game object), and two more randomly graphic componenets that in the AC menu editor are between the copied graphic element and the pasted element)
    -If I check the prefab, their gameobjects will be disabled even when they shouldn't (as on Editor, without Play).

    -Testing:
    Set the faulty enabled elements to be visibile on start.
    -Check on editor Play again.
    -Now all elements are found (no console errors)

    -On AC editor, duplicate another graphic element (this time, visible on start). Assign the new component. Play on Editor = No problems.
    -On AC editor, set the new graphic element that worked to visible on Start = false
    -Play on editor = That last graphic element cannot be found

    (Console log for the NEW elements when not set to visible at start):
    Cannot find UnityEngine.UI.Image for menu element exampleNameElement in Canvas exampleCanvas

     -> AC debug logger
    UnityEngine.Debug:LogWarning (object,UnityEngine.Object)
    AC.ACDebug:LogWarning (object,UnityEngine.Object) (at Assets/AdventureCreator/Scripts/Static/ACDebug.cs:39)
    AC.MenuElement:LinkUIElement<UnityEngine.UI.Image> (UnityEngine.Canvas,UnityEngine.UI.Image&) (at Assets/AdventureCreator/Scripts/Menu/Menu classes/MenuElement.cs:1398)
    AC.MenuGraphic:LoadUnityUI (AC.Menu,UnityEngine.Canvas,bool) (at Assets/AdventureCreator/Scripts/Menu/Menu classes/MenuGraphic.cs:110)
    AC.Menu:LoadUnityUI (bool) (at Assets/AdventureCreator/Scripts/Menu/Menu classes/Menu.cs:444)
    AC.Menu:TurnOn (bool) (at Assets/AdventureCreator/Scripts/Menu/Menu classes/Menu.cs:1980)
    AC.ActionMenuState:Run () (at Assets/AdventureCreator/Scripts/Actions/ActionMenuState.cs:102)
    AC.ActionList/<RunAction>d__47:MoveNext () (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:470)
    UnityEngine.MonoBehaviour:StartCoroutine (System.Collections.IEnumerator)
    AC.ActionList:ProcessAction (int) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:412)
    AC.RuntimeActionList:BeginActionList (int,bool) (at Assets/AdventureCreator/Scripts/ActionList/RuntimeActionList.cs:181)
    AC.ActionList:Interact (int,bool) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:283)
    AC.RuntimeActionList:DownloadActions (AC.ActionListAsset,AC.Conversation,int,bool,bool,bool) (at Assets/AdventureCreator/Scripts/ActionList/RuntimeActionList.cs:136)
    AC.AdvGame:RunActionListAsset (AC.ActionListAsset,AC.Conversation,int,bool,bool) (at Assets/AdventureCreator/Scripts/Static/AdvGame.cs:242)
    AC.AdvGame:RunActionListAsset (AC.ActionListAsset,int,int) (at Assets/AdventureCreator/Scripts/Static/AdvGame.cs:163)
    AC.MenuButton:ProcessClick (AC.Menu,int,AC.MouseState) (at Assets/AdventureCreator/Scripts/Menu/Menu classes/MenuButton.cs:705)
    AC.MenuElement:ProcessClickUI (AC.Menu,int,AC.MouseState) (at Assets/AdventureCreator/Scripts/Menu/Menu classes/MenuElement.cs:267)
    AC.MenuElement/<>c__DisplayClass38_0:<CreateUIEvent>b__0 () (at Assets/AdventureCreator/Scripts/Menu/Menu classes/MenuElement.cs:213)
    UnityEngine.EventSystems.StandaloneInputModule:ProcessMouseEvent ()
    AC.OptionalMouseInputModule:Process () (at Assets/AdventureCreator/Scripts/Menu/OptionalMouseInputModule.cs:193)
    UnityEngine.EventSystems.EventSystem:Update () (at ./Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/EventSystem.cs:530)
    

    **Conclusion: **

    -For some reason, on my versions (at the start of the thread), this happens:
    -Any new graphic element with visibility false at start is not found on runtime (both on editor and builds).
    -Previous untouched graphic elements not visible at start, keep working, if I don't touch them on AC editor.

    Workaround: Every new element must be visible at start, and hide it at start by code logic, then the reference is not lost.

  • Thanks for the follow-up - I'll attempt a recreation with these steps and let you know my findings.

  • Recreated, thanks.

    To test a potential fix: open up AC's Menu.cs script and look for the following, around line 957:

    UnityVersionHandler.AddConstantIDToGameObject <ConstantID> (field.gameObject, true);
    

    Just underneath, copy/paste:

    _constantID = field.GetComponent <ConstantID>().constantID;
    
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.