Forum rules - please read before posting.

Graphic Options Template (Download) Import Error

Hi folks, I imported the Graphic Options Template from the downloads page, but have received this error:

Assets\AdventureCreator\Downloads\Graphic options template\Scripts\GraphicOptions.cs(171,27): error CS1061: 'Dropdown' does not contain a definition for 'SetValueWithoutNotify' and no accessible extension method 'SetValueWithoutNotify' accepting a first argument of type 'Dropdown' could be found (are you missing a using directive or an assembly reference?)

Not sure how to proceed

This is on Unity 2018.4.36
AC 1.75.5

«13

Comments

  • Looks like it's a 2019 compatibility issue.

    I'll see if an adjustment can be made for 2018.

  • That would be great, thanks.
    I'm (hopefully) nearing the end of this project so I'm likely the last of the 2018 brigade.

  • I've looked into this, and it'd require too big a change to the structure to provide an official fix - however, I think I can point you in the right direction.

    Essentially, the package requires use of Unity's SetValueWithoutNotify function for Dropdowns, which allow Dropdown values to be set, without running their "On Value Changed" events. This was introduced in Unity 2019, however.

    For 2018, you'd need to look into replacing the Dropdown components with that of a subclass into which you can add the function manually.

    See karl_jones's 2nd comment in this thread. He covers a Slider, but it should be the same process for a Dropdown. Untested, but this code within DropdownEx may be enough:

    public void SetValueWithoutNotify (int val)
    {
            Set (val, false);
    }
    

    Inside AC's GraphicOptions script, you'd hopefully then just need to case the Dropdowns to DropdownEx before calling this function. I've updated the package to move all such calls to a single function, so you'd only have to do it in one place, i.e. replace:

    dropdown.SetValueWithoutNotify (value);
    

    with:

    DropdownEx dropdownEx = (DropdownEx) dropdown;
    dropdownEx.SetValueWithoutNotify (value);
    
  • So, I would create a new script similar to karl_Jones's (or your example) but call it DropdownEx rather than SliderEx, then edit the GraphicOptions script as per your instructions here?

  • In DropdownEX I have this error:

    Assets\Game\DropdownEx.cs(9,5): error CS0103: The name 'Set' does not exist in the current context

    In GraphicOptions I get this:

    Assets\AdventureCreator\Downloads\Graphic options template\Scripts\GraphicOptions.cs(201,37): error CS0030: Cannot convert type 'UnityEngine.UI.Dropdown' to 'DropdownEx'

    Here is what I have for DropdownEx, It's likely I'm missing something important:

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class DropdownEx : MonoBehaviour
    {
    public void SetValueWithoutNotify(int val)
    {
        Set(val, false);
        }
    }
    
  • Derive DropdownEx from Dropdown, i.e.:

    public class DropdownEx : UnityEngine.UI.Dropdown
    
  • Ah, yeah that helps. The only complaint I get now is:
    Assets\Game\DropdownEx.cs(9,9): error CS0103: The name 'Set' does not exist in the current context

    So Unity doesn't like "Set" in there for some reason. It's not that different from Karl's script though, only he uses sendEvent.

  • You're right - looks like Dropdown doesn't have an equivalent for Slider's Set function.

    You might be able to get around this by temporarily backing up the "On Value Changed" event, clearing it, then restoring it after setting the value:

    public void SetValueWithoutNotify (int val)
    {
        DropdownEvent oldEvent = onValueChanged;
        onValueChanged = null;
        value = val;
        onValueChanged = oldEvent;
    }
    
  • Okay, no errors after going with your suggestion there.
    However, the GraphicOptionsUI prefab has two missing scripts.

    https://imgur.com/a/Ps69SL8

    Do I have to put the DrodownEx and GraphicOptions scripts on there? I would have thought it was only GraphicOptions, but there are apparently two scripts missing.

  • The components should be Unity's own Canvas Scaler and Graphic Raycaster components. It may be because of the older version you're using - but remove and replace them and it should be fine.

    The DropdownEx script would have to replace the existing Dropdown components that the GraphicOptions component references.

    Thinking about it though, the code approach I mentioned above doesn't need the DropdownEx script - you could modify the GraphicOptions script directly.

    Try replacing its SetDropdownValue function with this:

    void SetDropdownValue (Dropdown dropdown, int value)
    {
        DropdownEvent oldEvent = onValueChanged;
        dropdown.onValueChanged = null;
        dropdown.value = value;
        dropdown.onValueChanged = oldEvent;
    }
    
  • Oh damn, it's actually every single element of the GraphicOptions prefab that has missing scripts - Panel, buttons, text etc. I tried deleting then re-importing the package without the edited script, but it's still the same. Not sure why they're not assigned when all the relevant scripts are in the project anyway? Probably my old Unity version, as you say.

    I would just go through and manually add the scripts, but the issue now is I'm not sure which element needs which component. Some have two missing scripts, others just the one, though the "Panel" element (directly beneath the main Canvas object) has three.

    :'(

    https://imgur.com/a/jAiA8dk

  • edited November 2022

    "Probably my old Unity version, as you say."

    Not just old, but 3 years older than the current LTS, which itself is nearly 1 yr old. It's a miracle if anything works at all on Unity 2018.4 as of late 2022...

  • Yeah I'm probably the last person using it. I heard too many horror stories regarding stability and it put me off updating back in 2019, now I'm too far gone...

  • Yeah, I discovered the hard way just this week that using anything later than the LTS (currently 2021.3) with AC and especially Opsive stuff is like a death sentence for the project...

  • I'd recommend staying away from post-LTS releases when it comes to a proper project. If you have encountered an issue with AC itself in a new version of Unity, however, please share details.

  • edited November 2022

    Okay, I deleted the DropdownEx script and replaced GraphicOptions' SetDropdownValue function with this as you suggested:

    void SetDropdownValue (Dropdown dropdown, int value)
    {
    DropdownEvent oldEvent = onValueChanged;
    dropdown.onValueChanged = null;
    dropdown.value = value;
    dropdown.onValueChanged = oldEvent;
    }

    However, using this code, I get these errors again:
    Assets\AdventureCreator\Downloads\Graphic options template\Scripts\GraphicOptions.cs(201,13): error CS0246: The type or namespace name 'DropdownEvent' could not be found (are you missing a using directive or an assembly reference?)

    and

    Assets\AdventureCreator\Downloads\Graphic options template\Scripts\GraphicOptions.cs(201,38): error CS0103: The name 'onValueChanged' does not exist in the current context

    btw I am replacing the code starting at line 199, hopefully I am replacing the right code.

  • Try this:

    void SetDropdownValue (Dropdown dropdown, int value)
    {
        Dropdown.DropdownEvent oldEvent = dropdown.onValueChanged;
        dropdown.onValueChanged = null;
        dropdown.value = value;
        dropdown.onValueChanged = oldEvent;
    }
    
  • Thanks Chris, no errors with this. However I still cannot actually test it out, as the prefab still has all the missing components.

    I know that Graphics Raycaster & Canvas Scaler are missing from the main parent object (GraphicOptionsUI) so that's okay, but the rest I'm not sure. I assume the objects starting with txt just need a Text component.

    If you can give me a rundown of the required components in just the beginning section (and the bottom buttons), e.g "Resolution" and "tglFullScreen" then I'm guessing I can replicate that for all the others.

  • There aren't any special components on each element type - just the standard that come with each by Unity. btnApply is an Image and a Button component, for example.

    For each element type, create a new one from Unity's UI toolbar and compare the components that are there.

  • Okay, I've made a bit of progress from making new elements and copying the contents of the disabled "Template" objects on them, such as for Dropdowns and Toggles.

    For some though, there's no default equivalent, as in the header/parent objects e.g VSync, Resolution (the actual dropdowns are child objects) etc. Not sure what to put on these?

    Also, in the top Panel (just called Panel), there are two missing components to replace that I am unsure of, as when you create a Panel from the UI toolbar it only has Image, Canvas Renderer & Rect Transform applied to it. What are these two additional components please?

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.