Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Visual Studio 2019 Unable to use & in watch

Discussion in 'Scripting' started by craigjwhitmore, Jun 25, 2021.

  1. craigjwhitmore

    craigjwhitmore

    Joined:
    Apr 15, 2018
    Posts:
    135
    I'm trying to get the address of any object, so in the Watch window, I'm prefixing a variable with & and I'm getting the message "Node not supported: '&test'"
    ie
    string test = "asdf";
    ...
    string test = "ssss";

    in Watch window:
    Name: test Value: asdf
    Name: &test Value: Node not supported:'&test'

    I have enabled address-level debugging within VS 2019, as per this post https://docs.microsoft.com/en-us/visualstudio/debugger/memory-windows?view=vs-2019

    Any suggestions would be helpful please.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,713
    I'm not sure this would affect Unity in any way, since Unity compiles your code before starting to run, using its own internal settings pretty much.
     
  3. craigjwhitmore

    craigjwhitmore

    Joined:
    Apr 15, 2018
    Posts:
    135
    I'm wondering if it's because of Unity that it doesn't allow memory visibility
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,713
    Not sure why you want an address in a managed language... but you can pin objects and get their address with System.Runtime.InteropServices, using something like:

    Code (csharp):
    1.     {
    2.         string s = "@kurtdekker";
    3.  
    4.         Debug.Log( System.String.Format( "str: '{0}'", s));
    5.  
    6.         GCHandle h = GCHandle.Alloc( s, GCHandleType.Pinned);
    7.         try
    8.         {
    9.             System.IntPtr ptr = h.AddrOfPinnedObject();
    10.             Debug.Log( System.String.Format( "ptr: 0x{0:X16}", (System.Int64)ptr));
    11.         }
    12.         finally
    13.         {
    14.             if (h.IsAllocated)
    15.             {
    16.                 h.Free();
    17.             }
    18.         }
    19.     }