Search Unity

Pointers in Unity

Discussion in 'Editor & General Support' started by empirebattles, May 20, 2013.

  1. empirebattles

    empirebattles

    Joined:
    May 17, 2013
    Posts:
    19
    I am looking to simulate a resource supply chain, by using a doubly linked list setup. I am wanting to have it set up, so the "Power lines" have a value that say weather or not they have power. However, the value would actually be a pointer that points to the value of the next power line object that it is connected to. And that value points to the next, and the next... it continues until it reaches a null (end of the line), or a power source. (this would probably go in 2 different directions, thus the doubly linked list, so that you could check both forward in the line, and behind)

    It wouldn't be difficult to do a constant check at each moment to check for 'power', but i was hoping for something a bit more 'live' responsive. This is all in my head right now, trying to see how it can play out, before i try to go into actual writing of it. I can do it in actual languages (which is a lot more difficult in the long run), but i was hoping i could do it with unity.


    Again, is it possible to setup variables as pointers? (NOT pointing to objects)


    Any answers, or "pointers" in the right direction would be GREAT!

    Thanks!
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You can just use LinkedList instead of making your own implementation, if that's what you're talking about.

    --Eric
     
  3. empirebattles

    empirebattles

    Joined:
    May 17, 2013
    Posts:
    19
    The issue with a linked list, is that the value of an instance, is typically a value. Similar to something like this:
    [*]==pointer

    I think i'd need to make the construct myself, in order to allow for the 'value' to actually point to the value of the next object in the list (which continues down the list, until the value points to the source, saying whether something is powered or not).

    This could probably be done by doing step checks to see if any given section is connected back to the source, but that is a check in a step, which i'm trying to avoid by having pointers, which will point to either a source, or a null.

    I doubt i'm explaining it as best i could, as i'm slightly tired, and distracted at the moment. if anyone is still unclear as to the concerns, lemme know so i can try to formulate my words better :)
     
  4. Jaimi

    Jaimi

    Joined:
    Jan 10, 2009
    Posts:
    6,208
    Are you sure? I'd assume that a value type would be boxed. Anyway, just wrap it in a class if it's not - then it's just a reference.