Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Issues with outdated code

Discussion in 'Editor & General Support' started by IAMSETH, Jul 31, 2018.

  1. IAMSETH

    IAMSETH

    Joined:
    Jul 28, 2018
    Posts:
    7
    Hi! So im pretty new to unity and recently purchased a asset from the store named the "first person adventure" kit. Whenever i load this asset however i get the error stating that the unityengine.application does not contain a definition for "iswebplayer". After some research i learned that apparently this code was meant for games to be built on a older player that unity no longer supports. Can anyone help me figure out what to do?
     
  2. Nicolas1212

    Nicolas1212

    Joined:
    Dec 18, 2014
    Posts:
    139
    Do you have the code of the asset? You should be able to edit it out and replace it with "#if UNITY_WEBGL" or similar (depending on if you want to keep that part of the code) - if you're not building for web, just remove it
     
  3. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    You'd comment out any areas of code specific to the old web player, which was removed from Unity.
     
  4. IAMSETH

    IAMSETH

    Joined:
    Jul 28, 2018
    Posts:
    7
    im really sorry guys im new to this. So basically i just put #if UNITY_WEBGL above the outdated code?
     
  5. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    You would probably want to contact the developer and just ask them if they have an update. Their asset page has a link to their website, which has their email address.
     
  6. IAMSETH

    IAMSETH

    Joined:
    Jul 28, 2018
    Posts:
    7
    I've emailed him\her three times in the last three days with no response. I know i am probably annoying them but i DID pay 25 dollars. Am i stuck with the asset if i cant get it fixed and if he doesn't agree to a refund?
     
  7. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Last I checked the Asset Store doesn't have a refund system. It sounds like the asset was last updated a couple years ago, and uploaded with a version probably older than 5.4. In the future you should be looking at what version of Unity an asset was uploaded using, and make sure it is not much older than what you're using. This is especially true for code assets, since older model or texture assets normally will work just fine.

    All you need to do is comment out any of the web player code in the asset to resolve this problem though. You'll need to understand C# so you don't break the logic of the script, but this is really a trivial task for anyone who codes in C#.
     
  8. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    Please show the specific code that is throwing the error, it is likely a simple fix.
     
  9. IAMSETH

    IAMSETH

    Joined:
    Jul 28, 2018
    Posts:
    7
    public void SaveGame()
    {
    if (Application.isWebPlayer) return;
    CurrentRoom = FindObjectOfType<Room>();
    if (CurrentRoom != null)
    {
    if (locationsStates.ContainsKey(Application.loadedLevelName))
    locationsStates[Application.loadedLevelName] = CurrentRoom.SaveState();
    else
    locationsStates.Add(Application.loadedLevelName, CurrentRoom.SaveState());
    }

    SaveGameData data = new SaveGameData();
    data.itemsId = InventoryController.Instance.items.Select(i => i.idItem).ToArray();
    data.notesId = JournalController.Instance.notes.Select(n => n.idNote).ToArray();
    data.tasksId = JournalController.Instance.tasks.Select(t => t.idTask).ToArray();
    data.completeTasksId = JournalController.Instance.completeTasks.Select(t => t.idTask).ToArray();

    data.locationsStates = locationsStates;

    data.globalValues = Values;
    data.locationName = Application.loadedLevelName;
    data.playerPosition = new Vector4Serializer(PlayerController.Instance.transform.position);
    data.playerRotation = new Vector4Serializer(PlayerController.Instance.transform.rotation);
    data.playerHealth = PlayerController.Instance.Health;
    data.equipedWearId = InventoryController.Instance.CurrentDress == null ? "" : InventoryController.Instance.CurrentDress.idItem;

    SaveLoadController.SaveGame(data);
    }

    the red underlined bit is the issue. Im more than happy to go through all the files and correct what i need to correct, i just need assurance on HOW to do so. Thank you guys\girls so much for the help.
     
  10. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Change:
    Code (csharp):
    1. if (Application.isWebPlayer) return;
    to:
    Code (csharp):
    1. //if (Application.isWebPlayer) return;
     
  11. IAMSETH

    IAMSETH

    Joined:
    Jul 28, 2018
    Posts:
    7
    that's it?... I do that everywhere there's an error? Im so sorry i wasted your time if thats all i have to do
     
  12. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    That is what "comment out" means.

    You don't necessarily do that for every error though, because in other cases it can break the script's logic or cause compile errors. For example, if the code was actually written like this:

    Code (csharp):
    1. if (Application.isWebPlayer)
    2. {
    3.     CurrentRoom = FindObjectOfType<Room>();
    4. }
    Just commenting out the line with Application.isWebPlayer in it will cause a compile error because these brackets aren't expected without the "if" statement above them. In this example you'd need to comment out the entire "if" statement, including the brackets and every line within the brackets.

    Code (csharp):
    1. //if (Application.isWebPlayer)
    2. //{
    3. //    CurrentRoom = FindObjectOfType<Room>();
    4. //}
    But if it was like this you'd need to analyze it a bit more:

    Code (csharp):
    1. if (Application.isWebPlayer)
    2. {
    3.     CurrentRoom = FindObjectOfType<Room>();
    4. }
    5. else
    6. {
    7.     DifferentRoom= FindObjectOfType<Room>();
    8. }
    So you'd want to comment out everything that is supposed to run if Application.isWebPlayer was true, but leave everything uncommented if it was false, while also removing extra brackets. So you'd do it like this:

    Code (csharp):
    1. //if (Application.isWebPlayer)
    2. //{
    3. //    CurrentRoom = FindObjectOfType<Room>();
    4. //}
    5. //else
    6. //{
    7.     DifferentRoom= FindObjectOfType<Room>();  //You still want this line to run
    8. //}
     
    Last edited: Aug 1, 2018
  13. IAMSETH

    IAMSETH

    Joined:
    Jul 28, 2018
    Posts:
    7
    What if other code is dependent on that "if" statement? Should i comment that out too?
     
  14. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    It really depends. You have to analyze what the code is trying to do and comment out anything that should only run if it were the webplayer, and don't comment out anything that should run if it were not the webplayer. The brackets, especially if the code has a lot of nested loops and if statements, is probably the trickiest part to sort out. I gave some simple examples above.
     
  15. IAMSETH

    IAMSETH

    Joined:
    Jul 28, 2018
    Posts:
    7
    OH MY GOD ITS WORKING YOU SIR ARE ACTUALLY GOD BRINGING DEAD CODE BACK TO LIFE THANK YOU SO MUCH!!
     
    Joe-Censored likes this.
  16. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Can I use this on my resume? :p j/k
     
  17. Fibonaccov

    Fibonaccov

    Joined:
    May 5, 2020
    Posts:
    58
    For anybody late to the party, it should have been replaced by:

    Code (CSharp):
    1. if (Application.platform == RuntimePlatform.WebGLPlayer)
    2.     return;