How to instantiate a prefab declared in one script, from another script

This is script one:

    public GameObject chatContent;
   //this gameobject is referenced in the editor

    public void Start()
        {
            AddMessage("This is ok");
        }
        void OnEnable()
        {
            EventSystemManager.StartListening("messageArrived", AddMessage);     
        }
        public void AddMessage(string message ) {
            print("One");
            GameObject remoteMessage = Instantiate(localMessagePrefab, chatContent.transform) as GameObject;
            print("Two" );
            remoteMessage.transform.GetChild(0).GetComponentInChildren<Text>().text = message;
            print("Three");
            DestroyMessage();
        }

145070-captureone.png

The method AddMessage executed in Start method works nice, and also i can execute AddMessage several time in the script. The problem is that if i execute this method AddMessage from another script it only get up to the print(“One”) in the method but the prefab is never instantiated. I have tried to do it by events and also referencing gameobject from the editor but nothing works. The method is executed but the instatiation fails with no errors.

This is script two with events:

 private async void onMessageHandler(string e)
    {
        serverMessage = JsonUtility.FromJson<serverMssg>(e);
        EventSystemManager.TriggerEvent("messageArrived", serverMessage.normmsg);
        await miaApi.queueAnim(serverMessage.normmsg);
    }

TIA!

if it prints one, but not two, there is an error on the line inbetween.
Try putting a debug breakpoint on that line and debugging it to see what is going on.
Its likely that your ChatContent or LocalMessagePrefab is null , has been destroyed somehow, or was null to start with.
If you are using unity 2018/2019 and new prefab flow. make sure your references are actually being saved to the prefab, (they might look ok in scene, but might be null in the prefab)

First of all thanks for the reply.
Im using unity 2018.4.6f1. I have check all the references and all seem to be ok (also in prefab).
Later i tried to debug with visual studio (breakpoint) but im not really sure what im looking for (
I am not used to using it), so i just comparing the same breakpoint from start method (that works) and from the eventTrigger.

So for me it looks like nothing is exactly null (only remoteMessage but it is ok), but maybe it is not getting the exactly same objetcs (It is my conclusion since the value is not exactly the same).

Also some things are in red but im not sure what it means.

Start method debug

EventTrigger Debug

Simple answer would be to either pass the reference to the object as a parameter to a method in the other script which stores it there, then that script can use it’s reference. If you want to modify the original, you can pass it by reference using the ref keyword. Kind of like:

method(ref objectReference);
...
void method( ref ObjectType objectReference) {
   do stuff with objectReference.
}