I cant instantiate a prefab from another script, it does nothing and gives me no errors. In the same "play" i can instantiate the same prefab from the same script multiple times but if i try to do it by executing the same method from another script it doesnt work.... i pass some variables and print them ( it work) but instatiation is doing nothing....please help!
I tried to solve it by:
public GameObject reference, UnityEvents and Ataching both scripts in one object
Script One
void OnEnable()
{
EventSystemManager.StartListening("printMessage", AddMessage);
}
public void AddMessage(string message )
{
GameObject remoteMessage = Instantiate(localMessagePrefab,
chatTransform);
remoteMessage.transform.GetChild(0).GetComponentInChildren<Text>
().text = message;
}
Script Two
public IEnumerator StartWebSocket()
{
using (ws = new WebSocket(serveradress))
{
ws.OnOpen += (sender, e) =>
onOpenHandler();
ws.OnMessage += (sender, e) =>
onMessageHandler(e.Data);
ws.OnError += (sender, e) =>
onErrorHandler(e);
ws.OnClose += (sender, e) =>
onCloseHandler(e);
ws.Connect();
for (; ; )
{
yield return null;
}
}
}
private async void onMessageHandler(string e)
{
serverMessage = JsonUtility.FromJson<serverMssg>(e);
EventSystemManager.TriggerEvent("printMessage",
serverMessage.normmsg);
await miaApi.queueAnim(serverMessage.normmsg);
}
The message is passed but instantiation do nothing.... The only thing i detect in debugging is that transform dissapears when tryng to do it from other script:
from the same script:
from another script:
Also there is a video (without sound) The video doesnt use events but is exactly the same behavior Video TIA!