How to soft reference an object in the level?

I have a player character and a ball placed in my level. I have an interface between the player and the ball which I use to update the ball’s position.

Currently, both the map and the player hard reference the ball object thus both loading it into memory. How can make it so that only the map loads the ball but the player can still reference it?

1 Like

If you’ve put the ball in the level, you can give it a tag, like this

image

then you can get a reference in your player with

Notice, it’s an actor reference, not a BP_Ball reference.

Even better ( in some sense ), you can spawn it from scratch like this

Hi. I have just implemented this but the reference viewer still shows both the map and player are hard referencing the ball (I did refresh the reference viewer :stuck_out_tongue: )

1 Like

Did you save the player? Did you make the variable of type ‘actor’?

You can’t avoid the map having a hard reference, unless you spawn the ball, because the ball is in the map… :slight_smile:

Yes, I always save all when I make edits.
I haven’t tried your second solution yet, I’ll give this a go shortly.

Can you show some pics?

This is on the begin play event on the ThirdPersonCharacter blueprint…

1 Like

I should point out that eventually I want to make a simple soccer game. I will make my own player character that will be used for all 22 players on the pitch. If I create a ball reference in the player bp won’t this load it 22 times?

1 Like

You example is correct. No, the ball will only be loaded once.

If the ball is going to be loaded all the time, it doesn’t need to be a soft ref anyway :sunglasses:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.