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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Help with message execution target

Discussion in 'Scripting' started by mrwilliams, Sep 30, 2015.

  1. mrwilliams

    mrwilliams

    Joined:
    Sep 23, 2015
    Posts:
    13
    Hi,

    I have two scripts on the same gameobject.

    One script does some stuff, and then I am trying to send that stuff to the other script also on the same gameobject.

    It was my understanding that a Message would be the best solution. I have implemented an interface etc, but when I try to execute the message, I get an error saying I cant access the GameObject.


    Code (CSharp):
    1. ExecuteEvents.Execute<INewMessage>(this.CurrentGameObject, null, (x, y) => x.SetNewCollection(PC));

    I have a public GameObject variable declared and drag the gameobject to it in the editor. Can someone please let me know how to specify the target, if indeed I should be using the GameObject in this way.

    Thanks,
     
  2. GroZZleR

    GroZZleR

    Joined:
    Feb 1, 2015
    Posts:
    3,201
    Can you paste the exact error message?
     
  3. mrwilliams

    mrwilliams

    Joined:
    Sep 23, 2015
    Posts:
    13
    HI GroZZleR,
    Thanks for the response - I have it fixed now, by making the call in the Update method. This is mostly me getting my head around how the objects referenced in Unity script is attached to the engine runtime.

    It's a little ugly needing to specify it directly in the update just so we have access to the primary thread in the engine, makes for some awful code, would be better if we could have dispatched/invoked into the thread from anywhere.

    But like everything in life, just need to work through the changes to understand them better.

    Cheers