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 castor · Dec 06, 2013 at 04:47 PM · listloopclasschildrenmirror

How to store children of a class inside that class

So I can't figure out the logical way of doing this.

In my project when a character talks to another one he starts a dialog. (class actorDialog).

At the end of that dialog I load the "children"as possible answers and display them for the player to chose. Then it plays that answer and so on.

Now my problem is how to actually write this. This is the class I created for it:

 class actorDialog {
     var title : String;                    //GUI title to select it
     var isAvailable : boolean;            //Is this dialog unlocked?
     var script :  List.<ScriptStep>;    //Text for the dialog
     var total : int;                    //How many types this dialog was selected
     var children : List.<actorDialog>;    //Possible replies to the dialog
 }

Now my problem is the actorDialog.children, since its a List of items of the same class inside the class itself. It makes an eternal loop that slows down Unity and I imagine it just doesn't make sense to have it that way.

Any other suggestions on how to go about it? This seems like the most logical way for me but probably I'm wrong...

Any help very appreciated!

Comment
Add comment · Show 24
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 Spinnernicholas · Dec 06, 2013 at 04:51 PM 0
Share

There shouldn't be an infinite loop there. It's a tree structure, so depending on your code, it will run until you hit all leaves(nodes without children) and then stop. How deep is your tree?

avatar image castor · Dec 06, 2013 at 05:01 PM 0
Share

That's what I would like, exactly like a tree structure! But where do I define how deep is supposed to go? (I'm imagining maybe 5 levels). I also realized that once I wrote this class, Unity became very slow doing Undo/Redo (taking about 10 secs) and the file size for the scene.unity increased about 4 times making me thing I shouldn't even be doing this or maybe it's supposed to be written in a different way?

avatar image Spinnernicholas · Dec 06, 2013 at 05:07 PM 0
Share

You don't set how deep the tree is. It just depends on how deep you build it.

avatar image Spinnernicholas · Dec 06, 2013 at 05:10 PM 0
Share

It sounds like you only need the current children at any given moment. Where is your code to fill the children list?

avatar image castor · Dec 06, 2013 at 05:14 PM 0
Share

This is what I would write as a code for it:

This would be the full class:

 class actorDialog {
     var title : String;                    //GUI title to select it
     var isAvailable : boolean;            //Is this dialog unlocked?
     var script :  List.<ScriptStep>;    //Text for the dialog
     var total : int;                    //How many types this dialog was selected
     var children : List.<actorDialog>;    //Possible replies to the dialog
 
     function actorDialog (script :  List.<ScriptStep>, actorDialogList : List.<actorDialog>){
         this.title = script[0].textLine;
         this.script = script;
         
         actorDialogList.Add (this);
     }
 }

And then on Start() I would write this:

 startDialogWife = new actorDialog (obj$$anonymous$$anager.actorPlayer, dialog$$anonymous$$anager.startDialogWife);
     startDialogWife.children.Add(askHowSheIsFeeling);
     startDialogWife.children.Add(askAboutWatchWife);
     startDialogWife.children.Add(askAboutHerPast);

and maybe some of them would have sub children.

But what I mean is, even before writing any of these extras, JUST writing the class makes Unity slowdown a lot.

Show more comments

0 Replies

· Add your reply
  • Sort: 

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

19 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

Related Questions

A node in a childnode? 1 Answer

Problem with arrays in a list 1 Answer

How to obtain a gameObject from an List with the name? 1 Answer

Looping through multiple lists 0 Answers

initialize (variable/List in Start() or Class?) 1 Answer


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