Full disclosure I’m a total noob with blueprints. So I asked chatgpt to give me a step by step guide to make one for me.
It was a total failure.
Basically I have a flatbed trailer that has 4 sockets on the surface to define the boundaries where I want to place a bunch of objects. Here’s how the conversation went with chatgpt…
In this step-by-step guide, I will show you how to create a Blueprint Component in Unreal Engine that places a list of objects in the middle of 4 sockets that are found on a static mesh and spaces them out based on their size.
Step 1: Create a new Blueprint Component
Open Unreal Engine and create a new Blueprint Component by going to the Content Browser and clicking on the “Add New” button. Select “Blueprint Class” and then select “Blueprint Component” from the dropdown menu.
Step 2: Set up the component
In the Blueprint Component Editor, go to the “Event Graph” tab. Create a new event called “Initialize Component” by right-clicking on the graph and selecting “Add Event” → “Initialize Component”.
Step 3: Add variables
*Add the following variables by right-clicking on the graph and selecting “Add Variable”: *
- A variable called “Objects List” of type “Array” and “Object Reference”. This will be used to store the list of objects that will be placed in the sockets.
- A variable called “Static Mesh Component” of type “Static Mesh Component”. This will be used to store the reference to the static mesh that contains the sockets.
- Four variables called “Socket A”, “Socket B”, “Socket C”, and “Socket D”, all of type “Scene Component”. These variables will store the references to the four sockets.
Step 4: Set up the Static Mesh Component
Assign the reference to the static mesh that contains the sockets to the “Static Mesh Component” variable in the Details panel.
Step 5: Set up the Socket variables
For each of the four Socket variables, click on it and in the Details panel, set its “Mobility” to “Static” and “Visible” to “False”. Then, use the “Attach to Component” node to attach it to the parent component. Make sure to set its Transform so that it is positioned at the desired location in the parent component.
To find the sockets on the static mesh component, use the “Get Socket Location and Rotation” node. Make sure to enter the correct socket names for each of the four sockets in the “In Socket Name” input pins.
Repeat this process for each of the four sockets.
Step 6: Modify the Initialize Component Event
In the Initialize Component event, use the “Get All Actors of Class” node to get all of the objects in the level that match the type of object that you want to place in the sockets.
Connect this node to a “For Each Loop” node and use the “Spawn Actor from Class” node to spawn a copy of the desired object for each element in the list.
Next, use the “Attach to Component” node to attach each spawned actor to one of the four sockets. To do this, use the “Get” node to retrieve each socket reference variable and connect each spawned actor to a different socket.
The next step is to calculate the total size of all the spawned objects. To do this, use a “For Each Loop” node to loop through each of the spawned actors and use the “Get Actor Bounds” node to get its size. Use a “Vector Length” node to convert the size to a scalar value and then use an “Add” node to add up the sizes of all of the spawned actors.
Use this value to calculate the spacing needed between each object. To do this, divide the total size by the number of objects, and then divide that by two.
Finally, use the “Set Actor Location” node to position each of the placed objects based on its size, the object’s index in the list, and the spacing value calculated in the previous step. To do this, use the “Get Socket Location” node to retrieve the location of each socket. Then, using the “Get Actor Bounds” node, retrieve the size of each object and use the index of the object in the list to calculate its position.
*To convert the size of the object to a scalar value, use a “Vector Length” node. *
Use an “Add” node to add the socket location of the desired socket to this position, and then subtract half of the total size of all the objects and the calculated spacing value. Finally, connect this result to the “Set Actor Location” node to position the object.
Step 7: Save and Test
*Save the Blueprint Component and use it in your level. Add a static mesh component to the parent component and assign the reference to the static mesh that contains the sockets to the “Static Mesh Component” variable. Then, add four sockets to the parent component and name them correctly to match the names in the node tree. Assign their references to the Socket variables in the Blueprint Component. *
When you play the level, all of the objects in the Objects List will be spawned, placed in the center of the four sockets, and spaced out based on their size.
Congratulations, you have successfully created a Blueprint Component in Unreal Engine that places a list of objects in the middle of 4 sockets that are found on a static mesh and spaces them out based on their size!
I tried to follow the steps but most of the variables/functions/events it asked me to create don’t seem to exist in UE5 (or UE4 for that matter).
Do these instructions make any sense to more experience blueprint makers out there? I could really use your help on this.
Thanks in advance.