Search Unity

Is there any way I can dump whole GameObject tree in runtime?

Discussion in 'Scripting' started by guyingzhao, Aug 6, 2020.

  1. guyingzhao

    guyingzhao

    Joined:
    Aug 6, 2020
    Posts:
    5
    I have been working for building a tool under iOS to get whole GameObject tree(including Scene).

    I have already learned out that I could create a pseudo object, just let MainCamera mount it, and inside the pseudo object I could just setup a RPC server and let the object do the rest work.

    However, I think the way above is too complicated and needs to be integrated by the original game project manually. So I'm looking for a way without involving the game project.

    I once thought using UnityFramework could help, but there were no helpful things(including unity_send_message).

    Hope to get something helpful ! Thanks a lot !
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,909
    What do you mean by "dump"? And what does it have to do with networking?
     
    StarManta likes this.
  3. guyingzhao

    guyingzhao

    Joined:
    Aug 6, 2020
    Posts:
    5
    "dump" means get the whole GameObject or Scene hierachy and those objects' information such as tag, name, text, rect

    "networking" is just a cross framework communicating method to deliver information above from inside unity to native, it's okay to use other mechanisms.
     
  4. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,909
    Ok but are you trying to serialize the whole scene hierarchy, or just traverse it in code?
     
  5. guyingzhao

    guyingzhao

    Joined:
    Aug 6, 2020
    Posts:
    5
    Actually I'm looking forward to a mechanism to get inside information of GameObjects, hierarchy is just a demonstration .

    Something like `unium` not quite matches my request.
     
  6. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,742
    Every GameObject has a Transform component that contains a list of its children. Recursively traverse it and and you can get all the MonoBehaviors on each one and print their types, etc. Reading it all out is trivial, reconstructing it all again not so much.
     
    Joe-Censored likes this.
  7. guyingzhao

    guyingzhao

    Joined:
    Aug 6, 2020
    Posts:
    5
    Yes, you are right. I have already implemented this, but I'm trying to find a way to do this in a released app instead of integrating those code to source code.
     
  8. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,742
    Everything I suggested above uses functions in the UnityEngine namespace so it will work fine in a released app.

    Am I misunderstanding what you are asking?
     
    PraetorBlue likes this.
  9. guyingzhao

    guyingzhao

    Joined:
    Aug 6, 2020
    Posts:
    5
    My target is to get inner information(such as hierarchy, text, rect of GameObjects) of an Unity app without having to deal with its source code.
     
  10. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,742
    I will say it again: Refer to my post above. You can do ALL of this. Start here:

    https://docs.unity3d.com/ScriptReference/GameObject.GetComponent.html

    Really... it can be done... it's like less than an hour of coding, even when you have to learn the concept of using GetComponent.
     
  11. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    I don't think the OP is looking for this. It sounds like he is talking about hacking someone else's game to get this information.

    The answer is there is no built in way to take someone else's released game and without access to the source code to be able to iterate through the hierarchy. I would assume it is possible if you developed your own system for examining the game's memory footprint, and figuring out how to identify everything you're looking for in memory. But if you had the skills needed to pull that off, you wouldn't be asking the question here anyways. So the answer is no.
     
    PraetorBlue likes this.
  12. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,742
    Oh Uncle Joe, I think you nailed it. I didn't notice that 'original game project' wording.

    Good luck OP! Check the modding forums. There are definitely a lot of tools out there for hacking and modding Unity games. This forum is for people using Unity as a product.
     
    PraetorBlue and Joe-Censored like this.