Spawn static mesh component AND have it update on a tick-like basis afterwards

Hey everyone. I need some help for a Space Exploration game I’m trying to make.
On Begin Play, I get all actors of class. this looks for “Markers” that have been placed in the world. I then run a for loop to spawn an arrow attached to the pawn for each “Marker” that was detected. I then want to be able to rotate those arrows so that they point at the “Markers” that were detected. So 1 arrow per Marker and I need to update constantly.

so far, I can get it to do this. So when I hit Play, it spawns an arrow on my ship and that arrow is pointed at the marker that’s out in the world.

blueprint looks like this.

PointToMarker function looks like this. This used to work when i just had 1 arrow and 1 marker. But i want it to be dynamic now and be able to detect as many markers as needed and have an arrow for each

my problem is that I cannot get those arrows to update rotation as I fly the ship around. Any help would be appreciated.

I think you answered your own question in the title. :smile:

You could spawn a new “marker arrow component” ONCE for each unique marker that you want to point to. If you derive it from “actor component” then it will have a tick function and it will tick every frame.

In this way your ship just makes sure that each of the markers has a component, and add/remove components as the number of markers changes, but then each arrow component’s tick function handles pointing it in the right direction each frame.

The conceptual change is that you don’t want to be spawning meshes. You want to be spawning a new “arrow marker component”, attaching that component to your ship actor, and telling it which mesh it’s supposed to be tracking.

The arrow marker component would then have its own mesh and its tick function would manage positioning that arrow mesh at whatever location/rotation each tick.

1 Like

I really appreciate the quick answer! And what you said makes total sense. So i put the arrow into a blueprint and am now spawning the actor and attaching to the ship. This works great. Problem I have now is how do i tell the Arrow blueprint which Marker blueprint to look for?

so this is me spawning the Marker Arrow blueprint and attaching it to the SpaceShip.

now im inside the MarkerArrow blueprint and im unsure how to tell it which Marker to look for.

Im hoping some of this is right and i didnt misunderstand everything you said :slight_smile:

thanks again!

I think rather than having BP_Marker_Arrow be an AActor, you want it to be UActorComponent. It’s a component that is attached to your ship actor. Components have tick functions too, not just actors.

I believe if you make it a component you can also give it a public method like “Watch this Marker” where you pass in a marker as an AActor* and then the component stores that in a variable it uses in place of your red question mark.

So ship spawns component, attaches component to itself, calls Component->WatchMarker(Marker) and then the rest is handled by the component’s tick function.

1 Like

Check out the “expose on Spawn” checkbox for particular blueprint variables.

Set this for your “Marker to Find” variable, and it should show up on the Spawn node in the Blueprint once you’ve selected your Arrow object class.

Also, I agree with @xl57, ActorComponent is probably a better choice than a sub-Actor. (Subclass StaticMeshComponent, for example.)

2 Likes

im sorry but im not really understanding what either of you are talking about now. I’m not really a blueprints expert so not seeing the solution visually is tough for me.

are you saying i should create a blueprint-class and choose actorComponent as the parent class? and this would be for the arrow that points to the marker? when i create that blueprint, it says its data only so im unsure how to attach my arrow static mesh to it.

Again, sorry if im really missing something simple here.

@jwatte described it better.

BP_Marker_Arrow should be derived from a UStaticMeshComponent (which is itself ultimately derived from ActorComponent).

So rather than just add a Static Mesh like you were doing initially, you’d add your custom static mesh component, which in addition to the static mesh also has the Tick function doing what you want each tick.

His suggestion of using the “Expose on Spawn” feature is also better than having to add a method to set the marker on your BP_Marker_Arrow.

1 Like