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
It looks like you're new here. If you want to get involved, click one of these buttons!
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
**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:
Just underneath, copy/paste:
sorry for the late response; Just where you told me to put that line it does nothing (_constantID is inside a { } where it does not affect anything
Not sure if related but I've got all sort of issues when duplicating prefabs that have Constant ID added. From my limited knowledge of how this works it appears the Constant ID gets duplicated so you have multiple objects with the same ID and strange things happens.
I've fixed these issues by opening the duplicated prefab, removing the constant ID script and add it again, then saving, also making sure the prefab doesn't have overrides of that constant ID (the unity overrides system where inside there is a value but outside there is another value)
unity 2023. please ignore if it doesn't have anything with hat you are trying to do
@Alarconte: I'm not sure I'm following - could you share a screenshot of where you made the amendment?
@dgames: Unfortunately, Unity doesn't provide a callback for prefab duplication - so ConstantID values will be retained here. You should at least be able to avoid removing/re-adding them, however, by choosing "Reset" from their cog menu in the Inspector.
I can't found the correct place for it to fix it.
And looks like my tries on fix in it defenitely with workaround don't work. Giving me a lot of "Random" trouble.
Looks like is affecting all new elements, often, even if they're enabled on start. If they're hidden with AC actionlists, next time they will open sometimes the reference will be lost, sometimes not. So I'm having all sorts of reports of "everything works fine" or "that and this is missing".
I tried the line you suggested on those two parts of the code, none would like to work (unless I've not tried hard enough).
Also, the Bug is CrossSave-Compatible. Meaning... if you have a Save with the menu working correctly, and Load one where the menu don't work, the menu will stop working on all saves. As said since the beginning, all is quite strange.
But all the menus with graphics elements that I've never touched since the updates, keep working without a fault.
Amend the code block you shared to read as follows:
If that doesn't resolve it, can you PM me the files and steps necessary to recreate the issue on my end?
I'm making a new menu that also uses graphic elements as way to show stuff so good moment to try.
For now, it does not solve the problem of graphic elements not visible on start. Some references (not all) get lost.
For now, I don't know if it will work with visible on start elements 'cause I need a variable of time of playing before knowing if "randomly" the reference will get lost.
But knowing that in the first case the fix doesn't work, is enough for now to know.
About files, I thought you had already recreate it. Or is the part where they get lost over time even if they're visible on start?
Additional questions;
Should the fix be save compatible, or the menus would still be broken on those saves? Would reassigning constant IDs fix save compatibility once we have a working fix?
Meaning, I tried the line in that position before, but on saves where menu reference were lost, they kept being lost, and due to the strange "random" nature of when the menus lose reference, it takes some times hours of testing to find if is fixed or not.
The code change I mentioned earlier was not applied correctly in your previous post. I did encounter an issue, and the fix I posted should resolve it, but if the issue persists on your end then I will need to work with your exact files.
The best way to ensure the issue is 100% reliably recreated, PM me a zipped project, along with instructions on how to recreate it.
Save data only references menus and elements by their internal ID number, not via Constant ID. They should be OK provided the element IDs remain the same.
Well, I've checked that fix and isn't working. For example, I start the game, I check all the menus working well, when the game changes scene and I check again some menu, suddenly references are lost there.
The first reason why in the first moment I told you that that line inside the loop could may not work is 'cause is greyed out on the Visual Studio, like the value wouldn't be applied to anywhere being inside that {}
About project files, I've never tried to send a part of a project so looks like a daring task right now, but I'll think on it.
I'm curious to know why you could reproduce part of the problem and that line of code fix it. This sudden bug on new menus are quite hindering my ease of mind on delivering new urgent releases so of course I'm eager to solve it....
Maybe the Unity version used is related?
The menu I was testing was one built from scratch, so no copy/pasting elements or constant IDs were involved. Is a generalized problem with all new Graphic Elements, while menus being made before the problem never lose references.
I think the constant IDs maybe related tho;
When inside the AC Menu Manager I have the prefab of the menu open and I select the graphic element linked on the AC Menu interface, working graphic elements point me (selects, highlight) in the scene view to the correct element, while references that will be (possibly) lost, point me to the prefab on the unity project.
Well, to be more precise, some of those menus that were bugged when I started the thread, never got bugged again after some constant ID reassigns and restarting unity until they got to a state where became stable and never lose references again. That's why this problem has been so hard to determine on my side.
This is at runtime? The Menu Manager fields should always point to the prefab.
There may be more than one aspect at play here. Rather than sending the project, try creating a test scene that demos the issue (two if a scene-change is necessary to show it). Then, create a .unitypackage creating this, the Managers, the UI prefabs, and any custom scripts attached to them. PM that to me, along with recreation instructions and I'll look into it.
No at runtime, in editor.
Sooner or later I have to fix the problem because I need to keep adding menus without that bug to show additional information, so if sending a recreable little project is the only way I guess I'll have to do it. BTW, I'm getting this random console warning from AC that is probably unrelated but better safe than sorry.
The problem is so strange. I, for other reasons, was checking what was the TextMeshPro text children of a graphic element linked Ui element on a menu (just checking what was written on it). I dind't thought the bug will affect the menu but... I guess I forget It affects everything I touch in an AC linked prefab.
Next time I run the game in editor, the Cannot find Unity.UI.Image console warning pops up. I close, open the prefab, and said element is disabled in the hierarchy. I enable it again. Ignore it, run again to check another thing.
The most strange thing is that.... In the prefab, the UI element didn't had a sprite (it is assigned via AC). But when checking the (deactivated at that moment) menu in the Don't Destroy "scene" at editor runtime, ****the sprite of the UI element was filled with the correct sprite (so basically, AC finds it, assigns the sprite, the warning pop up, and after that it won't just work properly in game. ****
Other times, after running in the editor, I check the prefab and the element is not disabled. (Doesn't make a difference tho).
PS: Then again, a major troubling issue here since the start is... Why AC working with an instanced prefab on editor/play runtime, could be modifying the original Prefab? Since the start I had the feeling it could may be related with the exact Unity version, some serialization problem... I don't know.