Move variable between blueprints

I’m using this socket plugin: TCP Socket Plugin in Code Plugins - UE Marketplace

I have a blueprint which is a child of TCPSocketConnection, I’m receiving data over TCP and am assigning the received data to a variable in that blueprint.

How do I get that variable in my main character blueprint? I set the variable to public in the tcp blueprint, and I’m trying to use the ‘Cast to’ feature but it just keeps saying cast failed.


Hi there @August_Rosedale, hope you’re well!

This topic has been moved from International to Programming & Scripting: Blueprint.

When posting, please review the categories to ensure your topic is posted in the most relevant space.

Thanks and happy developing! :slight_smile:

in various ways :slight_smile: maybe you want to search for the character in scene and pass the value to it. or maybe you make the character listen to an event sent by your tcp object and then react to the info received.

if you have both actors in scene, the tcp and the character before starting the level you can create a public variable in either of them where to add a reference to the other one. this is less elegant but it works anyway.

Not sure how to implement these. I have both the tcp actor and the character in the scene and have the variable being set in the tcp blueprint. How can I reference it in the character blueprint?

You don’t have anything to Cast. You need a reference to the specific character you want to affect. Usually to have a reference to something, you are going to want a relationship between them somehow.

It would be unusual for a player character to have an associated socket connection to something, so my guess is that you probably need to think about this from a different perspective.

What sort of data is associated with this socket? Why does the player character need it? The answer to these questions may help determine a better way to approach.

I’m using data from the socket to control the camera which acts as the players head. So that data from sensors can be used to move the head of the character.

So, conceptually, you’re replacing player input (or augmenting it) with input from the socket.

Normally Input comes in from the PlayerController, which then communicates with the PlayerCharacter to determine what the Character should do.

So, it’ll take a little bit of plumbing the information around, but you want it to flow logically so that the Socket is attached to the Controller in some way, then the data goes to the Controller, and the Controller tells the Character how to react to it.

Without knowing much more specifics, I’d setup an event in the Socket blueprint that is broadcast whenever data is received. Spawn the Socket from the PlayerController, and attach to that event. Then when you receive data from the Socket, it’ll go to the PlayerController, and where the PlayerController receives it, then it can tell the PlayerCharacter how to react.

Alternatively, you could just bypass the Controller, and do that in the Character, but the flow would be more consistent with other input, if it goes through the Controller first.

This unreal complete project has examples on how to pass data between actors/objects

is more of an organization thing. Are you doing VR? No need to reinvent the wheel, try uisng the starting VR project see how unreal did it