Error CS0029: Cannot implicitly convert type 'void' to 'int'

hi. I am probably a dummy but I keep getting this error and I am unable to fix it. I am working on a settings menu with player prefs using this code plz help

using System;
using UnityEngine;
using UnityEngine.Audio;
using UnityEngine.SceneManagement;
using TMPro;
using UnityEngine.UI;

public class SettingsMenu : MonoBehaviour
{
    [Header("Credits")]
    public int CreditsScene = 0;//when you want to play the credits open this scene 

    [Header("Audio")]
    public AudioMixer  AudioMixer;//this is for ajusting the volume of tracks on the audio mixer

    [Header("FPS Cap")]
    public Toggle VSync;//turn vscync on or off
    public TMP_InputField MaxFPS;//this is the max fps you can get
        private int FPS;//the fps cap

    [Header("Fps Monitor")]
    public GameObject FPSMonitor;//desplays the fps you are currently geting
    public Toggle FpsMonitorToggle;//will turn the fps monitor on or off

    [Header("Menu switching")]
    public GameObject SecondMenu;
    public GameObject FirstMenu;

    void Save()
    {
        PlayerPrefs.Save();
    }
    
    void Load()
    {
        //Audio Mixter Settings
        AudioMixer.SetFloat("Main", PlayerPrefs.GetFloat("Main", 0));
        AudioMixer.SetFloat("SFX", PlayerPrefs.GetFloat("SFXVol", 0));
        AudioMixer.SetFloat("VOICEVol", PlayerPrefs.GetFloat("VOICEVol", 0));

        FPS = PlayerPrefs.SetInt("FPSVal", PlayerPrefs.GetInt("FPSVal", Screen.currentResolution.refreshRate));

    }

    void Delete()
    {
        PlayerPrefs.DeleteAll();
        Load();
    }
   
}

it seems to have something to do with this line: FPS = PlayerPrefs.SetInt("FPSVal", PlayerPrefs.GetInt("FPSVal", Screen.currentResolution.refreshRate));

error: Assets\Scripts\Menu\SettingsMenu.cs(41,15): error CS0029: Cannot implicitly convert type 'void' to 'int'

Shouldn’t this only be a PlayerPrefs.GetInt call?

PlayerPrefs.SetInt doesn’t return anything.

You might also want to tidy this up to prevent this sort of typing mistake in the future, ESPECIALLY typing mistakes in the “FPSVal” part, because “FPSVal” will not match “FPSval”, etc.

Here’s an example of simple persistent loading/saving values using PlayerPrefs:

Useful for a relatively small number of simple values.

1 Like

It might prove beneficial to do what you are trying to do in several lines and variables shouldn’t be capitalised.

int fps = PlayerPrefs.GetInt("FPSVal", Screen.currentResolution.refreshRate);

PlayerPrefs.SetInt("FPSVal", fps));