Search Unity

Question System.OutOfMemoryException ???

Discussion in 'Scripting' started by Strafe_m, Nov 24, 2022.

  1. Strafe_m

    Strafe_m

    Joined:
    Oct 24, 2022
    Posts:
    72
    Soooo ^^ does not look good at all, I've just tried to add something to a Array List and unity freezes, after a solid 5 minutes I get that error. I'm gonna be honest, I don't understand this memory stuff, and I don't want to, my question is how do I fix it? Can I fix it?
     
  2. orionsyndrome

    orionsyndrome

    Joined:
    May 4, 2014
    Posts:
    3,106
    That 'something' is huge and surpasses your available memory. That's what it means.

    Please don't bother with programming if that's the case.
     
  3. Max-om

    Max-om

    Joined:
    Aug 9, 2017
    Posts:
    499
    There are things in a game engine you shouldn't need to bother with. Unity are a very manual engine.

    But managing memory allocation from your code is not one of those cases. It's called memory leak. For example you put objects in a list without removing them
     
  4. Strafe_m

    Strafe_m

    Joined:
    Oct 24, 2022
    Posts:
    72
    Not right now at least, got way more important stuff going on then learning what memory is...
    Well, the game crashed as soon as I put it in, so removing it doesn't come in the context
    Would I have to delete stuff from my pc, to build enough more available memory for unity?
     
  5. orionsyndrome

    orionsyndrome

    Joined:
    May 4, 2014
    Posts:
    3,106
    lol this is so funny it wraps around the gauge and feels sad instead. I now officially live in a world in which people make software while being unaware of what software even is.

    you should probably start with unity.
     
    Bunny83 likes this.
  6. Bunny83

    Bunny83

    Joined:
    Oct 18, 2010
    Posts:
    3,992
    You most likely have done something stupid and create countless things in an endless loop. We can't tell you what you did, how should be know? Please read your own thread again and tell us what piece of information you have provided that should tell us what you actually have done that caused your out of memory exception? You have provided literally zero information.

    Programming is about problem solving. It's one of the highest disciplines when it comes to problem solving. You just stated that you're not interested in understanding how any of that works. How do you think you're going to actually make a game with that attitude? It's like stating that you want to build a nuclear power plant but you can not be bothered learning about atoms, radioactivity, radiation or all that boring kind of stuff. You just want to bang some stuff together to create power... That would teach that gready power companies a lesson, right?

    To be honest, we spend already way too much time with this question, I'm off ^^
     
    BarriaKarl and MaskedMouse like this.
  7. orionsyndrome

    orionsyndrome

    Joined:
    May 4, 2014
    Posts:
    3,106
    aeeeooeoeoe kabooof ~~~~power~~~~
     
  8. Strafe_m

    Strafe_m

    Joined:
    Oct 24, 2022
    Posts:
    72
    No need for the taunts smh
    I most certainty stated how the problem occurred, maybe reading the first sentence of my original post will do you good :D

    I'm at the stage where I don't really care about how memory really affects my game, its got nothing to do with me I have no interest in taking this seriously and unity is just passion for me, nothing more nothing less, you got no right to give me a lecture on my attitude or anything else related to my game, you simply just saw syndromes post and without even reading my post, typed 2 paragraphs of..
    Oh sorry for wasting your time, next time, just move along
     
    Last edited: Nov 25, 2022
  9. orionsyndrome

    orionsyndrome

    Joined:
    May 4, 2014
    Posts:
    3,106
    It doesn't mean anything. You've got a fair amount of hints considering that you gave us almost nothing. Each and every of the hints you've got so far, suggest that you're supposed to learn more about what you're doing, otherwise you're stumbling in the dark, and nobody is going to help you with that, because you were very upfront in that you don't actually care about any of it. Why should we? I also have much more important stuff going on than helping some random person who wants me to be psychic.
     
  10. Strafe_m

    Strafe_m

    Joined:
    Oct 24, 2022
    Posts:
    72
    I'm not sure what else I can give you buddy, info doesn't have to be 3 paragraphs long, it can be as simple as a sentance as long as it's most revelant, I add 2 GO's in Start() to a list.
     
  11. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,858
    Generally when you have a problem pertaining to code, you post the problem code. It's the only way we can give any substantiated advice.

    This is the scripting sub forum after all.
     
  12. AnimalMan

    AnimalMan

    Joined:
    Apr 1, 2018
    Posts:
    1,164
    Where the code at


    Gimme dat CO
    Gimme dat CO CO Bit
    Gimme dat CO CO for your problem fixed


    Gimme dat CO
     
  13. Strafe_m

    Strafe_m

    Joined:
    Oct 24, 2022
    Posts:
    72
    Can you like .. off, your seriously pissing me off

    Anyways, it's really not that hard to picture in your head adding a GO to a list, but if you insist

    Code (CSharp):
    1. foreach(var pc in gm.playerControllers)
    2. {
    3.       if(pc.teamCode == 1)
    4.       {
    5.             Team1Players.Add(go)
    6.       }
    7.       if(pc.teamCode == 2)
    8.       {
    9.             Team2Players.Add(go)
    10.       }
    11. }
     
  14. AnimalMan

    AnimalMan

    Joined:
    Apr 1, 2018
    Posts:
    1,164
    Must be something wrong with your gm.PlayerControllers.
    Did you check the size of the list before calling for each?
     
  15. Strafe_m

    Strafe_m

    Joined:
    Oct 24, 2022
    Posts:
    72
    That's a bit of a problem, but all I can say even if the size is null, no reason for it to freeze and throw that error
     
  16. AnimalMan

    AnimalMan

    Joined:
    Apr 1, 2018
    Posts:
    1,164
    Well the size might be growing what if player controller is repeatedly being added to this list even though it’s already in the list
     
  17. Strafe_m

    Strafe_m

    Joined:
    Oct 24, 2022
    Posts:
    72
    Code (CSharp):
    1.     public override void OnEnable()
    2.     {
    3.         if (gm)
    4.         {
    5.             gm.playerControllers.Add(this);
    6.         }
    7.     }
    8.  
    9.     public override void OnDisable()
    10.     {
    11.         if (gm)
    12.         {
    13.             gm.playerControllers.Remove(this);
    14.         }
    15.     }
     
  18. AnimalMan

    AnimalMan

    Joined:
    Apr 1, 2018
    Posts:
    1,164
    So every time they enable and disable they could add another entry of themselves to the list
     
  19. Strafe_m

    Strafe_m

    Joined:
    Oct 24, 2022
    Posts:
    72
    Basically yeah.
    That's just used so when they die, they get removed from the list, and then after respawning they get added again
     
  20. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,858
    Stop hijacking someone else's thread. Get out of this one, and make your own thread.

    The problem is rarely due to one isolated bit of code devoid of any context. Often posting the whole script is better.

    It's quite likely you have an infinite loop due to some combination of parts of your code that indefinitely fills up a collection until it caps your memory. This is where debugging comes into play. Use break points, step through your logic bit by bit. This is a compulsory process as part of programming.
     
  21. Strafe_m

    Strafe_m

    Joined:
    Oct 24, 2022
    Posts:
    72
    Ahh now we're getting somewhere after 25 posts lol,

    I have been fiddling around with my code, and apparently restarting unity gets rid of the error, but the code I posted above is not really working. And I have a couple questions relating something which I think was the problem for this error.
    Again this is what I tried differently, though this called on the player it self.

    Code (CSharp):
    1.         if (currentGameMode.Name == "Knockout")
    2.         {
    3.             var tracker = KnockoutManager.Instance;
    4.             if (GetTeamCode() == 1)
    5.             {
    6.                 tracker.Team1Players.Add(this);
    7.             }
    8.             else if(GetTeamCode() == 2)
    9.             {
    10.                 tracker.Team2Players.Add(this);
    11.             }
    12.         }
    It's getting better, but still doesn't work. Let's say I'm team 1, I see both players under team 2 list, but if I'm switch editors, to player 2, who's in team 2, both players are in team 2 list.
    I really don't need that to be fixed as of now but apart from that these are some questions I have
    1. I'm having a problem with my GameManager.cs and managing GameModes, as you can see above, I'm checking if currentGameMode == ...
    This is really becoming a problem for all 5 game modes in my game, I can't have this being called 5 times to set the player up for that specific GameMode.
    Even if I have 1 GameManager.cs but a script which separatly manages each gamemodes gameplay, referencing a lot of the stuff from GameManager.cs to the GameModeManager is not wokring out, lets take playerControllers for example, players not being in the list but my reference gets called first etc.
    How do I manage GameModes effectively and references, How do I properly 'setup' the game before other scripts gets called, e.g all players being added to the playerController list.
    I think this is becoming a huge problem, code is getting very messy, and errors like these are happening because of ^^.. I'm struggling to add things as well, because "oh, what if that's not references properly", "what if this is being called before that has been"

    I want to be able to effectively manage 3 scripts
    Player.cs - GameMode.cs - GameManager.cs
    Player set's relevant info from GameMode.cs, which sets relevant info from GameManager.cs, which sets relevant player info from Player.cs etc
    I hope this makes sense
    Thanks in advance!
     
    Last edited: Nov 25, 2022