Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
0
Question by Iwa · May 02, 2013 at 02:37 PM · data storage

Stored data and GameObject

Hello everybody,

I'm working with Unity for a couple of months and I am actually facing a "problem". It's more a question than a problem but I would like to know how works the management of data.

Here is my point with an example: I would like to create an instance of the class Cat.

Cat is a simple C# class with functions and attributes.

 public class Cat : ISerializable{
 
    private string name;
    public string Name{
       get{return name;}
       set{name = value;}
    }
 
    private int age;
    public int Age{
       get{return age;}
       set{age = value;}
    }
 
    ...
 
    public Cat(string name, int age){
        this.name = name;
        this.age = age;
    }
 
    ...
 }

I instantiate my new cat Billybob with a little editor by giving the name and the age of the newborn.

Until there, nothing is special. My question is : Am i allowed to get my Billybob information without putting the instance Billybob in a MonoBehaviour attached to a GameObject in my Scene?

Or am I forced to made my Cat class inherit from MonoBehaviour and to create a GameObject Billybob and do an AddComponent("Cat") stuff?

The simple question is : do I need GameObject to access data that i've created :)?

Thanks for any help.

Iwa

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
0
Best Answer

Answer by whydoidoit · May 02, 2013 at 02:43 PM

No you don't. You just need to make the instances of it somewhere. That could be inside a MonoBehaviour or a static class.

Comment
Add comment · Show 3 · 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 Iwa · May 02, 2013 at 03:04 PM 0
Share

Thanks for your answer. I still wonder how do i get access to my information of Billybob if it is a static class? And what will my static class will look like?

avatar image whydoidoit · May 02, 2013 at 03:40 PM 0
Share
 public static class SomeClass
 {
     public static List<Cat> cats = new List<Cat>();
 }

Then to access it:

  SomeClass.cats.Add(new Cat("Billybob", 2));


avatar image Iwa · May 02, 2013 at 03:49 PM 0
Share

Okay thanks a lot for the explanation :)

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

13 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

Related Questions

Arrays vs. XML or SQLite: Fastest data storage/retrieval using JavScript/UnityScript? 0 Answers

android serialization weird path issue " IsolatedStorageException ", javascript 0 Answers

Scene management trick? 0 Answers

What are good ways to store a simple set of data/variables on an object 2 Answers

How to structure my project so that I can save/load information? 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