Struggling with transferring a variable (object reference) from one blueprint to another

Hi. I’m very new to UE4 so I’m trying to play around with the systems, so excuses this probably simple question but I couldn’t quite find an answer that works and that I understand.

Basically I’m struggling to transfer an object reference variable from one blueprint to another. I’m trying to make a snake-like thing out of balls and in order to get the segments to stay together in a line I need them to follow the one in front of them. I’m sure there’s an easier way to do this than what I’ve done, but this is frustrating me now so if possible I’d like to make it work.

The snake segments “should” only need to receive a correct object reference to work.

Here’s the code on the “head” of the snake, which in theory sets itself as the target to the first segment, then sets it as the target for the next one and so on.

I’m getting the error: “Blueprint Runtime Error: “Accessed None trying to read property Target”. Blueprint: PlayerSegment Function: Execute Ubergraph Player Segment Graph: EventGraph Node: Branch”

Thanks a lot!

Setting the reference to self on self is a bit redundant. If the one that spawns the next is the “previous” then you should use the Spawn node return value and set “Previous Segment” from this to “self”.

Oh I’m sorry I added that “self” when trying to debug and I forgot to switch back. I took a better picture now. The main problem is that the segments seemingly aren’t getting their target set, I’m just getting an error telling me “Blueprint Runtime Error: “Accessed None trying to read property Target””

Oh wow the whole time I had the logic on begin play, no wonder it was messing up, what a silly mistake lol. Thanks a lot!

Hi!

I think the problem is in the order of node execution. The BeginPlay in Player Segment runs during spawn. But the Target is set after it has been spawned.

I suggest to create a function in Player Segment called, let’s say, “Move Segment” which has the logic from Your BeginPlay, but run it after you set Target.

Also, I recommend to not call variable “Target”, because it become unclear which Target you mean :wink:

I just wanted to say thanks a lot, I’ve finally got it working now thanks to you =) It’s not much but it’s working at least