Hi there, i am quite new in Unreal.
The project that i want to complete is to spawn cars in a tunnel (about 20) and move them to a location. When the move finished i want to spawn a character next to each car and make the character to move to another location.
I have made the car spawn, move and stopped, making a row in the tunnel - this is what i want (the car is a simple skeletal mesh just to respect collisions and navigation - i do not care to make it as an unreal vehicle). But i cannot spawn the character next to each car (i want to simulate that every driver has to leave the car and move to an exit but if it just appear next to the car and do not “get out” it is OK for my project).
I have two solutions in my mind, but i cannot achieve them:
make 2 different spawners, one for the cars and one for the characters
make the character as a child or component in the car blueprint and make it invisible or disable and when i want make it appear and start to move.
Can anyone help on how can i make one of them or another better solution?
I suggest you create an array of the type of your “car bp” somewhere easily accessible, your gamemode for example.
Inside your car bp, add an Arrow component where you want your character to spawn.
Every time a car spawns, add it to the array you’ve created earlier, then create a function like this one:
When all your cars are spawned and reach their final location, simply loop through your car array and execute the function above for every item within it.
Thank you Aumenn2003 for the suggestion!
As i said i am quite new…so please can you give more details about how to create and call the array? (via casting to? or other method).
Sure thing.
First, you go to your gamemode blueprint (don’t forget it to set it up in your project settings too) and create an array of the same type of your car blueprint (for example Car_BP) like so:
To turn your variable into an array, click on the icon next to the variable type and choose the checkboard-like icon:
Now head to your car bp, click on add component and search for Arrow, position it next to your car where you want the character to spawn like this for example (the box is the car):
That arrow isn’t rendered in the game just so you know.
Now there is a handful of ways to communicate between blueprints but since we’re not running casts on every tick we should be fine. Do this to get a reference to your gamemode: (your gamemode’s name might be different)
Now it’s time to do this:
Within your car bp as always, add these nodes next the nodes we’ve created earlier like this:
At this point, we’ve set up every car that gets spawned in the world to be referenced in the gamemode’s array.
Now we head back to your gamemode blueprint and create a function that would help us to spawn a character next to every spawned car.
Idk how you check if all your cars are spawned but when they all do, simply call the function from your game mode like this:
And we’re done! I would suggest a good practice, if you intended to use a casted reference multiple times within a blueprint, it’s better to only cast once in your BeginPlay and save it as a variable like this:
I rushed through things a little but I’m here if you have more questions
You are f… awesome!! I really appreciate your help.
Just FYI (and to support my self…) 1st, 2nd, 6th and 7th images I have managed to implement! I hadn’t understood how to make the array but now everything is clear!
I want to go one step further as I said in my initial message, to make all the characters to move to a specific point. I want them to start moving after an event occurs (I can manage the event call and binding…at least as far as it works for me!). I have create in the character blueprint (“ThPassenger” for my project) a move to location node and I tried it to a single character in the game and it works fine. But when I call all the actors from a class (ThePassenger) the spawned characters do not move).
Here is a try with simple nodes to make characters move. (there is no custom event in this case and the delay time is greater than spawning characters time - just to make things go faster)
I don’t know much about the AI stuff but since your MoveToLocation node works fine with a single character, I assume that’s it just a matter of references.
Where did you place these nodes?
Why don’t you just add your characters to an array as they spawn?
These nodes are placed in Character (ThePassenger) blueprint.
Is there any difference if i add them in an array? I mean, since i want them to start moving some time after they have all spawned. But, if you suggest it…i have no reason to doubt!
This is kind of troublesome since these nodes would run on every instance of the character that exist in the world.
Here is what you should do instead.
Go back to your Gamemode blueprint, create another array of the type of ThePassenger, modify these nodes we created the other day:
Thank you for your suggestion.
I am trying to apply those nodes but my characters do not move and i get the following error when i stop the simulation:
Blueprint Runtime Error: “Accessed None trying to read property CallFunc_GetAIController_ReturnValue”. Blueprint: GMBlueprint Function: Move Character To Graph: Move Character to Node: Move to Location
The following images are all in the Gamemode blueprint (GMBlueprint)
No I have not! Why I should do this (and how…just create an empty AI controller blueprint and assign it to character blueprint?)
If I simple add the character (MyPassenger) in the level and add a node to move to a location, the character moves as expected (a default DetourAIController is assigned). The spawned characters are not moving with the above nodes in GM blueprint.
Nevertheless, i tried it (create an empty AI controller blueprint and assigned it to character BP) but nothing happened…
Sorry if I am missing something but as I said I am new in Unreal.
I really appreciate your help
Yew the characters spawned correctly as expected. Your first suggestion works straight forward.
It seems like the characters in array do not recognized as Pawns to obtain AI controller (as far as I understand)
To be honest, I don’t know anymore. I got it working on my side which means there might be just a little mistake that we’ve both overlooked.
I can assist through Teamviewer if you don’t mind.
Hahahaha!
Yew of course if your are able to do this it will be grateful!
EDIT
I found the solution…
Check this
I cant find the AImoveTo node… but when I edit in Character BP the “Auto possess AI” and set it to “Placed to world or spawned”…finally worked!!!