Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by DeadlyTitan · Jan 16, 2017 at 11:52 AM · stackoverflow

Stack Overflow Exception Unity C# Scripting

so i am making my first game in unity and i hit my first wall. i am watching some guides to make the game and i ended up with stack overflow exception. any help is really appreciated. i am using unity 5.5.0f3 x64 bit Personal version (free version), with microsoft visual studio that came along with the unity installation. thank you very much and sorry for long post.

This is the error StackOverflowException: The requested operation caused a stack overflow. BaseCharacterClass.set_CharacterClassName (System.String value) (at Assets/Scripts/Character Classes/BaseCharacterClass.cs:11).

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class BaseCharacterClass
 {
 
     public string CharacterClassName
     {
         get { return CharacterClassName; }
         set { CharacterClassName = value; }
     }
     public string CharacterClassDescription
     {
         get { return CharacterClassDescription; }
         set { CharacterClassDescription = value; }
     }
     public int Health
     {
         get { return Health; }
         set { Health = value; }
     }
     public int Mana
     {
         get { return Mana; }
         set { Mana = value; }
     }
     public int Strength
     {
         get { return Strength; }
         set { Strength = value; }
     }
     public int Speed
     {
         get { return Speed; }
         set { Speed = value; }
     }
     public int Intelligence
     {
         get { return Intelligence; }
         set { Intelligence = value; }
     }
     public float AttackChance
     {
         get { return AttackChance; }
         set { AttackChance = value; }
     }
     public float Defense
     {
         get { return Defense; }
         set { Defense = value; }
     }
     public float Evasion
     {
         get { return Evasion; }
         set { Evasion = value; }
     }
     public float Resistance
     {
         get { return Resistance; }
         set { Resistance = value; }
     }
 
 }


warrior class

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class BaseWarriorClass : BaseCharacterClass
 {
 
     public BaseWarriorClass()
     {
         CharacterClassName = "Warrior";
         CharacterClassDescription = "Melee Fighter, Later Can Evolve Into Breserker, Barbarian Or Knight";
         Health = 10;
         Mana = 0;
         Strength = 5;
         Speed = 5;
         Intelligence = 0;
         AttackChance = 50;
         Defense = 5;
         Evasion = 0;
         Resistance = 0;
     }
 }
 
 

GUI

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class TestGUI : MonoBehaviour
 {
 
     private BaseCharacterClass class1 = new BaseWarriorClass();
     private BaseCharacterClass class2 = new BaseMageClass();
 
     // Use this for initialization
     void Start()
     {
 
     }
 
     // Update is called once per frame
     void Update()
     {
 
     }
 
     void OnGUI()
     {
         GUILayout.Label(class1.CharacterClassName);
         GUILayout.Label(class1.CharacterClassDescription);
         GUILayout.Label(class2.CharacterClassName);
         GUILayout.Label(class2.CharacterClassDescription);
     }
 }
 
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by KoenigX3 · Jan 16, 2017 at 12:29 PM

You don't need these set / get methods in the BaseCharacterClass. If those variables are public, they can be modified without the methods. Right now they don't have any meaning.

You could use them for example, if you have a private variable, and you want to access it by a public set / get method.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image DeadlyTitan · Jan 16, 2017 at 04:03 PM 0
Share

Thank you very much.... that worked like a charm :)

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

86 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

[Solved] Recursive Method causing Stack Overflow 1 Answer

StackOverflowException: The requested operation caused a stack overflow. Please can someone help me solve this. 1 Answer

Unity freezing?? 2 Answers

problem with stackoverflow exception 2 Answers

Stack Overflow error in recursive method 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges