Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Text of textmesh not changing in event

Discussion in 'AR' started by problemsolver, Jun 3, 2020.

  1. problemsolver

    problemsolver

    Joined:
    Jun 3, 2020
    Posts:
    4
    Hello,

    im currently building a client for the hololens to receive messages from a RabbitMQ server. If is send a message from the server i successfully receive it when i write it into my Debug Console. After the message is received and printing on the console i try to set the text of a TextMesh object, but its not working out.

    Any ideas what i am doing wrong?

    Code (CSharp):
    1. [SerializeField]
    2.     private TextMesh receivedMessageText;
    3.  
    4.     IConnection connection;
    5.     IModel channel;
    6.  
    7.     EventingBasicConsumer consumer;
    8.  
    9.     private object _lock = new object();
    10.  
    11.     UnityEvent myEvent;
    12.  
    13.     // Start is called before the first frame update
    14.     void Start()
    15.     {
    16.         state = "not set";
    17.  
    18.         ConnectionFactory factory = new ConnectionFactory();
    19.         factory.HostName = "localhost";
    20.         factory.UserName = "guest";
    21.         factory.Password = "guest";
    22.         factory.VirtualHost = "/";
    23.         factory.HostName = "localhost";
    24.  
    25.         factory.Uri = "amqp://guest:guest@localhost:5672/";
    26.  
    27.         connection = factory.CreateConnection();
    28.         channel = connection.CreateModel();
    29.  
    30.         channel.QueueDeclare(queue: "hello", durable: false, exclusive: false, autoDelete: false, arguments: null);
    31.  
    32.         consumer = new EventingBasicConsumer(channel);
    33.         consumer.Received += (ch, ea) =>
    34.         {
    35.             var body = ea.Body;
    36.  
    37.             string message = Encoding.UTF8.GetString(body);
    38.  
    39.             Debug.Log("Got message! Body: " + message);
    40.  
    41.             Debug.Log("Model: " + consumer.Model);
    42.  
    43.             // set text from producer
    44.             receivedMessageText.text = message;
    45.  
    46.             SetMessageText(message);
    47.  
    48.  
    49.             state = "message received";
    50.             Debug.Log("State: " + state);
    51.         };
    52.  
    53.  
    54.         channel.BasicConsume("hello", true, consumer);
    55.         Debug.Log("Channel open: " + channel.IsOpen);
    56.     }
    57.  
    58.     private void SetMessageText(string message)
    59.     {
    60.         Debug.Log("Set TextMesh to: " + message);
    61.  
    62.  
    63.         receivedMessageText.text = message;
    64.  
    65.     }
    Thanks for helping.