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();
}
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!