How to return value from BP to C++?

Hello everyone,
I have 2 actors in my level: HttpServer and Machine. The goal is to control Machine movement using Requests, which are sent to HttpServer and get RequestResponse whether Machine collided with anything or not.
I have code in HttpServer.cpp, which gets request, parses it, fires an Event in HttpServer Blueprint, which is calling binded Event Dispatcher from Machine to move it in given direction (Using SetWorldLocation), and after it creates Response and returns it to user.
I tried using OnComponentHit Event to detect collision, variable which I pass into Event by reference and Gate, to register collision only when both OnRequest and OnComponentHit are fired, but OnComponentHit is triggered too late, after the Response in c++ is created. I tried calling BP Function instead of firing an Event from c++, because Function has return unlike Event, but it is not possible to use OnComponentHit Event within a function. I tried using SweepHitResult of SetWorldLocation, but the collision is not detected in this case.
Could anyone tell me the way to get an information whether Collision has happened or not back in c++ script to be able to return it with RequestResponse?

I think the best option is to pend sending the C++ web response until you know that the movement has taken effect.

(Actually, the best option is to not use Http for networked physics, but that’s a different discussion :smiley: )

E g, create some blocking primitive, wait on it, unblock it when simulation has finished, and then send the response.

Alternatively, you can run a manual collision check by checking primitive overlaps in some particular position, by calling the collision functions directly. Just make sure you don’t collide with yourself!

Yes, thank you!
I also considered this idea: to pass reference to variables isCollided and isFinished into Event, so that change of their value in BP would also change their value in C++, but I am still figuring out how to pass a reference into Event, because it also doesn’t seem possible, since it understands ‘&’ sign as an output and therefore not letting me to use it to pass a reference…

References in blueprint are dangerous, because the underlying object needs to stay alive for the duration of the call.

If your function runs as part of an event graph, and the event graph uses a Delay node or other asynchronous dispatch, then the execution may be suspended, similar to a coroutine. Yet, the reference doesn’t keep the underlying object alive (or, it may even be a reference to a stack variable!)

I recommend keeping some kind of object that represents the lifetime of the request, and communicating state using properties on that object. That way, the object can be kept alive by whoever needs it, for as long as they need to.