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 /
avatar image
0
Question by Ravart · Jun 09, 2017 at 12:18 AM · valuesreferences

Tree Structure: update root element (reference) for all classes

Hi everyone!

I might have a trivial problem, but I'm not finding the right "wording".

Lets say I have different nodes, which are connected like this

A - > B -> C -> D

All class objects have a root node, referencing to D*, means A returns D or C returns D. Therefore adding a new element like this

A - > B -> C -> D

F - > B

F should also return D

Now here is the thing, if the tree changes to

A - > B -> C -> D -> N

F - > B

all objects should now reference to N instead of D, without looping through parent of parent to get the final root. All objects should link to a "value", that can be changed by any object (static isn't a good option, there are different trees). Probably I require something like a pointer, but C# is different.

Hope someone can point me in the right direction :) Thanks

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 IgnoranceIsBliss · Jun 09, 2017 at 05:51 AM

I think the best answer is "Don't".

Unless you're constantly requesting the root asset, I wouldn't bother - make it traverse the tree to find the root and you'll never be wrong. Each asset that way only holds a reference to it's immediate parent.


If all of the objects in the scene are part of the same hierarchy, then you can just use a static variable that you hold the root node in. That way when you update the static, each node knows about it. However, if you have multiple hierarchies, this will fail.

public class Node { public static Node Base = null; }


FInally, you could always create a class that holds a value...

 public class RootHolder {
     public RoodNode N;
 }

Then you could pass the same RootHolder object (instead of a reference to the root) to each and every node. Then when you update the node, update it once and every object will change.

That's a lot of memory usage for what might be a small payoff though. As I said, unless you're requesting the root node a LOT, there should be a more efficient way around it.

Comment
Add comment · 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

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

66 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

Related Questions

How to change a value of a reference object variable after a while ? 0 Answers

how to pass and retrieve values to 2 dimensional array 1 Answer

Getting parameter values sent to a method c sharp script 0 Answers

rigidbody2D.velocity returns zero values 1 Answer

How to catch Unity values in Android EDI ? 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