Using: Unity 2022.3
Using: Adventure Creator 1.81.7
Problem
In the Objectives system, the default ObjectivesUI prefab, when modified to show additional graphics, appears to lose its links to those graphics when going into game play mode in the Unity Editor.
Attempting to Achieve
I'd like to present additional information about objectives to the player when a menu that tracks them is displayed. In this case I'd like to show a completion mark next to each Objective / Sub-objective as it gets completed, in addition to the default StateType in the ObjectivesUI prefab.
Expected Outcome
I'm expecting to be able to modify the existing ObjectivesUI prefab (AC Game Editor tab > Menu > Objectives menu > Linked Canvas Prefab (with a Source of Unity UI Prefab): ObjectivesUI (Canvas))
In this way I should be able to enhance the presentation to the player and customize the information about each objective / sub-objective.
Observed Outcome
I am able to modify the ObjectivesUI prefab in the Unity editor, and to create additional game objects in the hierarchy for the elements of the menu. I am also able to edit the Menu Elements in the AC Game Editor panel, and "link" each new element to each new object in the prefab.
However, on using Play Mode in the Unity editor, when the UI Menu is instantiated, to appears to lose its connection to the intended graphic in the project folder (the graphic is set as a UI Sprite). Instead, Unity displays the default color instead of the source image.
Question
Is there another step I need to perform / complete to keep that source image in the menu, or is there something going on in the background code that can be adjusted to ensure that the source image selected when editing the prefab also appears in Game Play mode?
Screenshots link (hope this works) > https://imgur.com/a/l5iPYcf
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
A Little More Testing
Screenshots link > https://imgur.com/a/adventure-creator-objectives-ui-not-linking-game-play-mode-unity-l5iPYcf
It looks like this is a case of the Graphic correctly linking - as AC is affecting the assigned Image.
The issue is that there is no texture assigned in the Graphic element's "Texture" field. At runtime, AC will apply this texture to the Image component - even if that texture is null.
It's a good case for the opposite behaviour, however: if no texture is assigned here, then AC should probably just leave the assigned Image alone and instead just control its visibility.
You can get this behaviour by opening AC's MenuGraphic script and replacing its SetUIGraphic function (around line 447) with the following:
Does that give the intended behaviour?
LOL, I'm banging my head on the desk now.
Of course! It makes perfect sense to interpret the Texture field in the AC Game Editor to mean "use this texture to display in your new menu element." It makes so much more sense to assign the appropriate texture there than to try to embed one in the ObjectsUI prefab.
I wasn't sure what that texture slot was for. The existing Selected Texture element on the menu didn't use one so I was ignoring this one, but now I think I see how you intend it to work.
That ^^ fixes the issue I was having. Thank you for that!
Thanks also for providing the suggested code. In order to provide a test for that for you, I opened the MenuGraphic.cs file and commented out the existing SetUIGraphic function, and instead pasted in the code you provided above.
I'm not able to test it any further than that, however. It gives two compile errors in the Unity console, as it recognizes neither the argument uiImage nor uiRawImage.
If I were to suggest a change for future versions of AC, I would suggest adding a tool tip in the AC Game Editor > Menu > Graphic (new) > Texture heading.
Something to the effect of "assign a texture here to display in the menu element."
Updated Images > https://imgur.com/a/adventure-creator-objectives-ui-not-linking-game-play-mode-unity-l5iPYcf
Thanks again, Chris. Here's hoping your week is excellent!
What's the exact compilation error that appears in the Console?
Either way, I'll make the adjustment in the next release.
I'm getting the following two errors (one for each line number):
[path]\MenuGraphic.cs(line number,9): error CS7036: There is no argument given that corresponds to the required formal parameter 'uiComponentHideStyle' of 'MenuElement.UpdateUIElement(T, UIComponentHideStyle)'
Replace the two problematic lines with: