Spawn Actor That Tracks Player Movement

Hi People :slight_smile:

I’m trying to create a shield pickup for my game so when main character picks up a shield, he gets protected from enemy bullets by a force field for a certain period of time (e.g 10 secs). I’ve tried many ways to do it, but none worked properly.

So below are corresponding blueprints and please let me know if you have any ideas on how to achieve that spawned Force Filed BP TRACKS player movement when he runs, turns etc.

Elements of the equation are :
Shield pickup BP: When player collides with box collision around shield, it destroys shield itself and initiates a Shield Sphere Event (Custom Event)

Third person character BP: Within Third person character BP, custom event spawns actor Force Field BP that protects main character from enemy bullets. THIS IS WHERE THE FORCE FIELD BP SHOULD BE PROGRAMMED TO FOLLOW PLAYER MOVEMENT AND THEN DESTROY ITSELF AFTER 10 SECONDS!

Enemy bullet BP: The enemy bullet programmed to take main character damage

Force field BP: Below is force field BP that is programmed to destroy enemy bullet when they collide.

352400-force-field-bp.png

So the question would be what has to be done under TPC BP so that Spawned Actor BP follow player around?? The Force Field itself works OK so basically just needs to be following the main dude.

Any help would be great and much appreciated :slight_smile:

Many thanks,

Why not just enable the shield in the player character. That way, you know it has to follow them.

That being said, if you really want to do it as a spawned actor, you can make it follow the player with finterp.

Hi there thank you for your answer.

Yes so basically I’ve tried doing that in few ways but unfortunately none really worked.

I’ve tried integrating Vinterp to as well (pls see below the screenshot) as per your suggestion but got the same results which is when player picks up the shield pickup, the force field gets spawned and stays in one place. That one really puzzles me :slight_smile: So if you have any suggestions, please let me know.

Thanks a lot

Can you show your code? ( you left out the pic ).

Aha sorry, yes sure pls see attached

Likely answer is probably just some other exotic :slight_smile: combination of location code attached to Spawn actor or/and Set actor location

You need to have vinterp on tick, like in my example :wink:

Heyy thanks that worked just now Im getting the below annoying error for some reason :slight_smile:

Blueprint Runtime Error: “Accessed None trying to read property CallFunc_FinishSpawningActor_ReturnValue_1”. Blueprint: ThirdPersonCharacter Function: Execute Ubergraph Third Person Character Graph: EventGraph Node: SetActorLocation

Pls see attached the actual blueprint: I’ve created a custom event since the shield pickup has a delay and destroy at the end. Thanks

It’s probably because once you’ve destroyed the actor, the tick event is still running :slight_smile:

Umm don’t know really since even if I remove Delay and Destroy, I still get the same error massage…It works perfectly though when I’m playing in editor but when the game is stopped, I get that annoying error message.

There must be a way to do that and is probably simple as per usual :stuck_out_tongue:

What needs to happen with that error is always the same. Click on the last linkable word on the right hand end, it will take you to the node that is getting the empty value.

Yes that would be Set Actor Location Node but unfortunately don’t know what to do with it to fix that error

Or to be more specific the issue is likely a pointer going from return value pin of Spawn Actor From Class Node into target pin of Set Actor Location Node

Coming in late to this party… but ClockworkOcean is right… You are probably destroying an actor whose location you are still trying to access and you get the Null reference. Also, even if don’t destroy as you say, you’ll get that error because on the first ticks you will try to set a location to an actor THAT DOESN’T EXIST YET, because you haven’t spawned it. I would suggest doing a IsValid check on the spawned object you get out of that node. This will avoid the error at the end.
I would also suggest perhaps saving a reference to that object you spawn for good housekeeping. Maybe create a variable in your blueprint (ActiveSpawnedShild) or something like that. Populate it when you have a shield, empty it when you don’t, or just always check if it’s valid first before you do anything with it.

Boom thanks that worked with IS VALID Node. Obviously after a 100 tries :slight_smile:

Thank you for that one…

Below is end blueprint snip for anyone that might be interested one day…