At this point I felt like I am spamming question on the forum, I am really sorry, but this problem has stuck me for days
The Blueprint communication in UE is actually so complicated, at the first place I thought making a variable public would fixed most of the problem, and now I don’t even know how and when to use a event dispatcher, cast to, blueprint interface…
Right now I want to make my car start moving only after I press my widget button, I think I success to make the on_click button work with event dispatcher, As you can see in the picture, I want to cast to my BP_vehicle and to use it’s Move Object Event,
but couldn’t make it work, I don’t even know what kind of object I should input, I saw many youtube videoes but I don’t understand how to do it.
Which method to choose for communication depends on what we’re doing. None is better than others, they are situational, circumstantial and serve specific purposes; there’s also overlap between them, some are used in tandem.
I want to make my car start moving only after I press my widget button
would it be OK if it was the car BP that creates the widget? Is the widget supposed to be a part of the car, belong to it?
This would lead to using an Event Dispatcher or Direct Comms.
perhaps you have a game where there are 20 cars and only 1 widget. Remote controlled micro machines or the player can drive many cars.
can we control more than 1 car at a time?
can we control objects other than cars?
Each of those situation could lead to using different combination of comms method.
Do tell us a bit more about the big picture you have in mind. How is this all going to work?
If all you need is to click button → trigger action in the underlying actor:
Hi, @Everynone, Sorry for the late reply, for the situation right now, I am a complete rookie, I try to make a traffic simulator with a easy way and to build the function step by step.
My first idea is to create a player controller, the defaultpawn class is something really decent IMO except if I hold my left click it would move the screen which is not something I want, anyway I choose it as the parent class.
I add a left_click_input event to record the mouse location with a vector array, I want to use all these locations to spawn spline and let the vehicle to follow the path, right now I create a actor blueprint called BP_Vehicle and copy a simple follow_spline function from youtube, I can let the vehicle to follow the splines I created before playing the level ( Starting the game? What should I call it? ).
I want to change the function to let player create the spline in the game with left click themselves, and also write a function to let the vehicle start following the spline only after player click start button.
So right now the follow_spline event is inside the BP_Vehicle, since later on I want to let player select to multiple vehicles and to create their own spline separately, so I think it is a good idea to write the check_start_button function in BP_player controller, meanwhile the follow_spline in BP_Vehicle, am I correct?
Now when I click the start button it would interact since I use the event dispatcher, but the problem stucking me is that I don’t know how to use the cast_to_BP_Vehicle, as you can see in the picture.
#edit
I just realized maybe in my case, we need to write a follow_spline function with interface, is this true?
Now when the player left click with their mouse, the game will record the current selected actor, and only if I select the vehicle and press the start button, the vehicle will start following the spline.
Now my goal is to let player build the vehicle’s spline in game and separately, I am able to let player build a cube with right click, but I don’t know how to let player build spline separate by different vehicles, and I also don’t know how to let all the splines connect in the game, It would be very nice if you give me some advise on that topic.
I don’t know how to let player build spline separate by different vehicles
A vehicle BP can hold an array of spline components, these can be added dynamically as seen above. You could probably include this in the vehicle BP if the vehicle needs the spline exclusively for itself.
meanwhile the follow_spline in BP_Vehicle
I’d say so, since each vehicle needs to be independent.
how to let all the splines connect in the game
You can’t really connect them. You line them up and switch between them. They can sit in an ordered array if we’re following a linear path.
For interconnecting crossroads you could build a node-like system where splines have overlapping volumes at their relevant intersection-capable spline points.
To cast (test + convert) you need a reference, how do we know which instance out of the 1000 vehicles in the world do we mean?
using interface to solve the problem
How did you get the Current Actor then?
Because if you have a reference, you can cast; and if you have the reference of the correct type, you do not even need to cast.
You’d use an interface if you wanted to communicate with unrelated classes. If you had planes, trains, cars and pedestrians in the game, and ordered them to MoveForward, each could implement the interface message differently move in a unique way. Other applications of interface comms exist, too, ofc.
Hi, I am reading your previous post, about this question, I add a right_click_input event to record the BP my mouse right click on, oh wait, so this is the object reference cast_to needed!
Cast To checks whether the actor is of the type we specify and then lets you treat it as if it was, indeed. A failed cast is as useful, sometimes you want to click on cars only, not on trees.
If you clicked a tree and sent it an Interface message to MoveForward, that’d be awkward. Luckily, interfaces messages fail gracefully and nothing happens.
From now on, if anything runs into the road intersection sphere, that custom event will fire and produce a reference of who was involved. And that custom event can be in another blueprint, too.
I now understand to create a spline, the add_spline_component only need to called once, the splines now being created and show up correctly, but there is something wrong with it, I think the target of add_spline_component is wrong.
as you can see, the spline is like stuck with the vehicle, but I thought it should stick on the ground.
Actors own components. The target should be the actor that needs to own that component.
If left as is, this actor instance will own this component instance.
If it’s moving erratically, it’s most likely because the spline is moving with the car. Is that what you mean? Run the show splines command to visualise them run time. I was on mobile so I could hardly see it. Yeah, that’s what is happening.
You can either set the spline comp to live in world space or move just the car mesh instead of the entire actor.
By default, components live in the actor’s relative space - move, rotate and scale with it. If you move the actor, the component also moves. If the TL samples location along a spline and the actor is on the move… that’d create the chaos we saw, with the car spazzing out.
You can set any component to be Relative or not: World = Absolute.
Hi, I try add a cube infront of player controller, if I set it to world type it stay at the xyz I given to it; if I set it to relative it would always be infront of me.
But I can’t make the BP_Vehicle work well, I try to make spline absoulte, but it isn’t doing anything, I might set something wrong;
I then try to only move the mesh and it collision box, it kinda work, but then the Vehicle’s Z location seems to be drop down a bit, The Vehicle’s Z location before moving is fine, don’t know what’s wrong with that.
This way you do not need extra nodes and the transform acts as World Coordinate. The car is too low because the spline is too low, move it where it needs to be.
If you want the spline to always start where you placed the actor:
Either offset the mesh to ride higher or place the spline higher. You could probably use car mesh component bounds for that. Potentially something close to:
If you’re updating just the mesh location, the spline can be relative to the actor. What I suggested before was an or thing. It seems you’ve applied both.
Hi, Thank you for answering all these answer to me, I change the location to absolute inside the detail panel of Add_Spline_Component, and the car now moves correctly.
Now there is one more question, point 1 is what we get from get_actor_location, but the car always tend to auto create a point 2 spline point at the right hand side of the point 1, creating a V_shape, then it would connect point 2 to the where we have the second click, which makes the animation not perfect, do you know why this happen?
When you add a spline component, it already comes with points 0 & 1. So when you click for the first time to add a new point, you actually add point 2.
add a small debug function to visualise what is going on:
Hi, You have helped me solved like thousands of problem in just one post, really really thank you for spenting these much time to help me, my UE project can now at least make a vehicle follow player’s spawn spline, I guess phase 1 is done.
For the next phase I would try to separate the spline create system, then adding a UI for player to spawn mesh to create the map, then maybe in the end to add the vehicle speed system, but I should work hard and try to do all these things by myself, other that getting helps all along, but again really really appreciate you patiently try to understand my question and answer them logically.