Hello guys,
After countless hours of trying to figure out what’s up with this one, I’m coming over to share the fun!
I have a “custom” UNetworkConnection class (made it child of UObject). Inside, I have a few methods, such as ReadPackets, WritePackets, Update, etc. And a FSocket, used to connect to my game server. I also have a PlayerController C++ class, extended by a PlayerController Blueprint. In the PC C++ class, I have methods such as Connect, Disconnect, Update - all of them exposed to blueprints… which calls my UNetworkConnection class methods.
No issue connecting, sending packets, reading packets, however, after a short time - between 10 to 60 seconds, things go nuts and here’s what happens:
http://puu.sh/p6xYp/1322d343a5.png
It appears the FSocket from my UNetworkConnection somehow gets dropped by the garbage collector for some reasons. It looks like it’s null. Yet we’re passing through the nullptr check.
I can’t explain it. I just don’t get it. Apparently we need to make things UProperty as to ensure the garbage collectors do not dumbly recycle things that actually are still referenced and in use, but that is possible only for UObjects and… FSocket isn’t one.
The pointer to the FSocket isn’t nulled anywhere by myself. The reference is always there. I landed on a post from (TCP Socket Listener, Receiving Binary Data into UE4 From a Python Script! - C++ - Epic Developer Community Forums) where he’s answering to someone experiencing the same problem as I am. At first, I had my functions exposed to blueprints inside a GameState class, after seeing this post I moved things to a PlayerController as suggested but no success.
I have no idea what to do anymore. Note that I can trigger this error (instead of waiting 10 - 60 seconds after connecting) simply by connecting, opening up the console and running the command OBJ gc (to force-execute garbage collection).
Please help!