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. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

Error CS0117: `GameManager' does not contain a definition for `Instance'

Discussion in 'Scripting' started by shyamlondonconsolidated, Aug 26, 2018.

  1. shyamlondonconsolidated

    shyamlondonconsolidated

    Joined:
    Apr 1, 2018
    Posts:
    36
    I am currently using the Corgi Engine by more mountains.

    I have the following scripts within the project;

    A GameManager.cs which controls the number of gems
    A PlayerController.cs which calls the GameManager.Instance.UseGem();

    I get this error message;
    Assets/Imports/Player/PlayerController.cs(182,53): error CS0117: `GameManager' does not contain a definition for `Instance'


    The PlayerController script is currently highlighting GameManager.Instance has an issue?
    Code (csharp):

    1. if (hit.collider != null)
    2. {
    3. Vector3 ropeVector = attachmentPoint - transform.position;
    4. swingTangentNormalized = Quaternion.Euler(0f, 0f, -90f) * ropeVector.normalized;
    5. attachmentPoint = hit.point;
    6. GameManager.Instance.UseGem();
    7. if (GameManager.Instance.CurrentGems == 0)
    8. {
    9. if (GameManager.Instance.CurrentGems == 0)
    10. {
    11. LevelManager.Instance.KillPlayer(GetComponent<Character>());
    12. }
    13. /*else
    14. {
    15. GameManager.Instance.LoseLife();
    16. }*/
    17. }
    This code was working perfectly. However once I imported in the official IAP plugin app, this script is broken and GameManager.Instance is not being recognised which I dont understand why?

    Any help would be much appreciated.

    Kind Regards,

    SLC
     
  2. shyamlondonconsolidated

    shyamlondonconsolidated

    Joined:
    Apr 1, 2018
    Posts:
    36
    Is there an alternative method to use rather than an instance?
     
  3. Doug_B

    Doug_B

    Joined:
    Jun 4, 2017
    Posts:
    1,596
    I believe that you have given code from the PlayerController script. That shows the call it is making into the GameManager to find a property called
    Instance
    .

    So the thing to do is to look into the GameManager code. Does it have an Instance property? Is it public? Is it called "instance" instead (lowercase first letter)? etc.
     
    MisterSkitz likes this.
  4. shyamlondonconsolidated

    shyamlondonconsolidated

    Joined:
    Apr 1, 2018
    Posts:
    36
    The GameManager.cs doesnt have an instance property. The playercontroller should just be able to call the function from the gamemanager script?


    This line below worked perfectly before I added in the official IAP plugin app. Now the "Instance" is not being recognised after I do this.
    if (GameManager.Instance.CurrentGems == 0)


    The GameManager script;

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4. using MoreMountains.Tools;
    5. using System.Collections.Generic;
    6. using MoreMountains.InventoryEngine;
    7. using UnityEngine.SceneManagement;
    8.  
    9. namespace MoreMountains.CorgiEngine
    10. {
    11.  
    12.  
    13.     [AddComponentMenu("Corgi Engine/Managers/Game Manager")]
    14.     public class GameManager :     PersistentSingleton<GameManager>,
    15.                                 MMEventListener<MMGameEvent>,
    16.                                 MMEventListener<CorgiEngineEvent>,
    17.                                 MMEventListener<CorgiEnginePointsEvent>,
    18.                                 MMEventListener<CorgiEngineTimeScaleEvent>
    19.     {
    20.        
    21.         [Header("Settings")]
    22.         /// the target frame rate for the game
    23.         public int TargetFrameRate=300;
    24.         [Header("Lives")]
    25.         /// the maximum amount of lives the character can currently have
    26.         public int MaximumLives = 0;      
    27.         /// the current number of lives
    28.         public int CurrentLives = 0;
    29.         /// the name of the scene to redirect to when all lives are lost
    30.         public string GameOverScene;
    31.         [Header("Gems")]
    32.         /// The maximum number of gems that the player can use
    33.         public int MaximumGems = 0;
    34.         /// The number of gems remaining
    35.         public int CurrentGems = 0;
    36.  
    37.  
    I have been trying to resolve this for the past 2 days but with no solution and I dont understand why the IAP plugin has broken the code?

    Any insight would be much appreciated!

    Kind Regards,

    SLC
     
  5. Doug_B

    Doug_B

    Joined:
    Jun 4, 2017
    Posts:
    1,596
    Ok, so according to this Corgi spec, the
    Instance()
    is given by the PersistentSingleton base class.

    Do you still have a copy of the previous version of the API? Maybe check that
    Instance()
    was in there and is not in the latest version. If that's the case, either hack the method back in, or go to the author and ask for their help.
     
    gothicserpent likes this.
  6. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,599
    As @Doug_B notes above, look inside the PersistentSingleton base class to see if it has a .Instance property. The docs show it as .Instance rather than a function like .Instance(), but perhaps that's out of date.

    It's also possible that the IAP module brought in a differently-namedspaced class called GameManager and that one is what you're finding, although it seems you have some Corgi namespacing in your code. You can always explicitly namespace out the entire reference until you find what you're looking for.

    I recommend using source control at all times (git works great with Unity) so that you can undo breaking changes like this trivially and go back to a known good working state and then recontinue you work.
     
    Doug_B likes this.
  7. shyamlondonconsolidated

    shyamlondonconsolidated

    Joined:
    Apr 1, 2018
    Posts:
    36
    Many thanks for the responses!

    At the start of the player controller script, if I were to introduce this below, would this call the instance from the game manager?

    There are a few scripts within the corgi engine which use the Singleton

    Code (csharp):
    1.  
    2.  
    3. public class PlayerController : Singleton<PlayerController>, MMEventListener<CorgiEngineEvent>
    4.  
    5.  
     
  8. Doug_B

    Doug_B

    Joined:
    Jun 4, 2017
    Posts:
    1,596
    In all honesty, I simply don't know for sure given the code as pasted above. However, my feeling would be that it is difficult to see how that would fix it.

    If your client code is expecting the GameManager to be offering an "Instance" method / property, then it has to offer it somehow (either directly, through inheritance or some sort of extension method maybe).

    Are there any release notes for the product that mention this? Has the developer told you to make client side changes as part of this new release? If this is causing a lot of grief, can you revert back to the previous version? Do Corgi offer support? Might be worth considering your options.
     
  9. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,140
    If you mouse over the GameManager part of GameManager.Instance it should tell you it what script it's pointing at.

    In this case it should be using MoreMountains.CorgiEngine.GameManager

    If it doesn't show the namespace part, it's pointing to the wrong script.
     
  10. shyamlondonconsolidated

    shyamlondonconsolidated

    Joined:
    Apr 1, 2018
    Posts:
    36
    Many thanks Doug and Brathnann!

    I included a namespace CorgiEngine in the relevant scripts as well as adding the singleton to the public class which resolved it!
     
    ZainTech and Doug_B like this.