#Web request- visual scripting
1 messages · Page 1 of 1 (latest)
Heyoh!
I am not very proficient with Visual Scripting, but I think you need to use the GetDownloadHandler AFTER you sent the request.
the problem is I can not connect it to send request - do you have any idea how can I connect it directly after send request ?
In normal code the request needs to be sent and then you need to wait till it is complete (error or success) and THEN read from the download handler
https://docs.unity3d.com/6000.1/Documentation/ScriptReference/Networking.UnityWebRequest.Get.html
No idea how this is done in visual scripting but there is probably an equivalent to coroutines/async.
tbh if you are doing web requests and understand those just write normal code
should be the same in visual script. just need to find the node names (and "human naming OFF option is recommended, so node names are similar to c# naming)
I have not worked with "web requests" yet - so i cant be much of a help in this topic.
Tell me - What does it do? "see my backend messages " ---> what is the message you are trying to see in console?
maybe this answer can help with the answer.
this is what you want to see in the console, when clicking a button occurs?
First thing is first: is that button being triggered when you click on it?
with graph open, and play mode ON... click the button, and then the graph node "On Pointer Enter" should turn bluish - confirming that event is fired. Once you have that WORKING, then you move to the next nodes.
let us know.
here's an example. how graph looks like when the node is flowing. make sure this one changes color when you trigger it as well
Because I suspect it is not working, because you are using a "game object find" by name string... and this is not an efficient way of getting button events
the platform that I am gonna deploy the project in does not support C# code- it is monaverse- and I thought probably with visual scripting I can do it.
messages comes from smart contract deployed- and once it sends the signal backend which deployed in "Render "with that adress send the message to unity (later monaverse) and the hidden object will become visible- "I did this with C# and the backend and the logic work properly- but as monaverse does not support C# code in playground I need to create visual scripting
yes now temporarily I inserted a button to just check and fix visual script- once it is fixed I will eliminate the button and will test the smart contract deployed in Sepolia test net manually from Remix IDE.
after receiving the messages from backend- I think I should have a Json parsing node (not again sure ) that order the object to be visible- now backend says :""1stStoryWindows":false" once smart contract sends true" it will become :""1stStoryWindows":true" and the object will become visible
All unity platforms support c# otherwise the engine would not function... What's the actual built target platform?
Some platforms need il2cpp but that doesn't change c# support
Seems Monaverse does not support !
No idea what that is and I have no idea how you plan to make this work
@serene viper I tried to record some videos- in this video you can see that when I have a C# I can fetch data- also before I had just C#- no visual script at whole- now even inside this visual script I can not use C#- so I should replace all the logic with visual script- Thank you so much for your help
You got it working, by mixing c# and visual scripting - I see.
If you want pure c#, then that c# has to be converted into visual scripting. if you paste the code here maybe we can translate it into uVS
But I'm wondering... why do you want to make changes in the scene via a web URL and not within unity?
also - what makes you think if c# won't work - visual scripting will work?
using UnityEngine;
using UnityEngine.Networking;
using System.Collections;
public class WindowVisibilityManager : MonoBehaviour
{
public GameObject firstStory;
public GameObject secondStory;
public GameObject thirdStory;
public GameObject fourthStory;
private string apiUrl = " ......";
void Start()
{
// All window objects are set to inactive (hidden) in the Unity Editor before build.
// No need to hide them by code; they start hidden.
StartCoroutine(PollBackend());
}
IEnumerator PollBackend()
{
while (true)
{
UnityWebRequest request = UnityWebRequest.Get(apiUrl);
yield return request.SendWebRequest();
if (request.result == UnityWebRequest.Result.Success)
{
var json = request.downloadHandler.text;
var dict = JsonUtility.FromJson<WindowVisibilityDict>(json);
if (dict._1stStoryWindows) firstStory.SetActive(true);
....
}
else
{
Debug.LogError("Backend not reachable: " + request.error);
}
yield return new WaitForSeconds(2f); // Poll every 2 seconds
}
}
}
// Helper class for JSON parsing (adjust field names if necessary)
[System.Serializable]
public class WindowVisibilityDict
{
public bool _1stStoryWindows;
....
}
justinmelillo told me - he is the CEO of monaverse
it is based on work prograss- it is not a game-
@serene viper this is the overal logic :"The window GameObjects are set as inactive (hidden) in the Unity Editor before building and uploading to the metaverse. The Unity Visual Scripting logic periodically contacts the backend server (every some seconds)to check which windows should be revealed. As soon as the backend returns true for a window (such as "1stStoryWindows": true), the script or visual script will set that GameObject to active (visible) in the scene."
Checking.
Here's the graph that makes it work. Make sure coroutine is set ON in the triggered event that runs this.
Thank you so much the first part which is fetching data is working perfectly -then we have json parsing node(similar) to force the object...
Err hmm