Moving Meshes at Runtime

Moving this here as it's still a blocker for me and I guess it's more complicated as the more general UE modding server suggested coming back here to ask again - Do you have to change anything else meshes to update? E.g. setting visibility off and on again, or disabling/re-enabling collision? When updating node location, such as using
ResourceNode->SetActorLocation(NodeData.Location);
ResourceNode->SetActorRotation(NodeData.Rotation);
MeshComponent->SetWorldLocation(NodeData.Location);
MeshComponent->SetWorldRotation(NodeData.Rotation);
ResourceNode->SetActorLocation(NodeData.Location);
ResourceNode->SetActorRotation(NodeData.Rotation);
MeshComponent->SetWorldLocation(NodeData.Location);
MeshComponent->SetWorldRotation(NodeData.Rotation);
I notice that setting this location/rotation for both works if its during their spawn, but it doesn't appear to update their location once they've already been spawned. I'm also not entirely sure if I have to update the MeshComponent separately from the Actor or not, since the mesh is attached to the actor when I spawn them using
ResourceNode->SetRootComponent(MeshComponent);
MeshComponent->RegisterComponent();
ResourceNode->SetRootComponent(MeshComponent);
MeshComponent->RegisterComponent();
tried again with
ResourceNode->SetActorLocation(NodeData.Location, false, nullptr, ETeleportType::TeleportPhysics);
ResourceNode->SetActorRotation(NodeData.Rotation, ETeleportType::TeleportPhysics);
MeshComponent->SetWorldLocation(NodeData.Location, false, nullptr, ETeleportType::TeleportPhysics);
MeshComponent->SetWorldRotation(NodeData.Rotation, false, nullptr, ETeleportType::TeleportPhysics);
ResourceNode->SetActorLocation(NodeData.Location, false, nullptr, ETeleportType::TeleportPhysics);
ResourceNode->SetActorRotation(NodeData.Rotation, ETeleportType::TeleportPhysics);
MeshComponent->SetWorldLocation(NodeData.Location, false, nullptr, ETeleportType::TeleportPhysics);
MeshComponent->SetWorldRotation(NodeData.Rotation, false, nullptr, ETeleportType::TeleportPhysics);
the method is being called and is updating these appropriately, and the mesh is moveable (also as an aside, weird how AActor::SetActorRotation is missing the fields the other methods have ... (https://dev.epicgames.com/documentation/en-us/unreal-engine/API/Runtime/Engine/GameFramework/AActor/SetActorRotation/1) I can't find anything in UE documentation or forum/reddit/etc that seems to deal with this
Epic Games Developer
AActor::SetActorRotation | Unreal Engine 5.5 Documentation | Epic D...
Set the Actor's rotation instantly to the specified rotation.
16 Replies
Beef
BeefOP4d ago
Pictured above - mesh position didn't update 😐
No description
Phenakist
Phenakist4d ago
are you able to send the file so I can take a look? I assume these are static meshes? there could be an issue if they mesh is set to static instead of moveable or doesn't fire an event post begin play as a side note, you might be able to use a set transform, which has your loc & rot combined
Beef
BeefOP4d ago
It's spread across a couple files, but I'll give more context The meshes set to moveable, but about firing an event ... maybe? The set transform is also a clever idea
Phenakist
Phenakist4d ago
transform does the exact same thing, just easier to have in one, less repetition on your end for the same purpose! I am just thinking if tick is not enabled or it doesnt have an event dispatch equivalent, it will never be enacted to update not touched much C++ for satisfactory atm, so not fully in the know just generally seen a lot of thgeir classes have tick off by default not on
Beef
BeefOP4d ago
ah! tick is certainly not enabled ... at least for my code anyways
Phenakist
Phenakist4d ago
try updating it per game tick to see if it just works at all, if it does work you can then move it to be a called event instead knowing it should fire
Beef
BeefOP4d ago
https://pastebin.com/puaFwfme is the original spawning logic, which spawns the meshes with the extra rotation/location information if it has been raycast within the save before
Pastebin
SpawnCustomResourceNodeSolid - Pastebin.com
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Phenakist
Phenakist4d ago
ill take a look; my C++ is not that strong, so just trying to help where I can will see if I spot anything! 😄
Beef
BeefOP4d ago
https://pastebin.com/MrxxZ67b This is where I update the mesh locations based on the results of CalculateLocationAndRotationForNode which handles the raycasting/finding average elevation/rotation
Pastebin
UpdateWorldResourceNodes - Pastebin.com
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Beef
BeefOP4d ago
This 2nd method is where the SetActorLocation/Rotation and SetWorldLocation/Rotation don't update I think something related to tick is probably the culprit Even if you don't or my shitcode goes over your head, I appreciate the ideas as its something else to investigate :hypers:
Phenakist
Phenakist4d ago
haha thanks, yea hopfully I can help! it's like a semi known language, I can read it and understand whats going on and speak words but I will miss parts of the sentance structure xD
Beef
BeefOP4d ago
yeah there's some things related to tick for actors/components, so you are probably right. I'm somewhat unfamiliar with the concept being new to UE5 still, but this is something that there's answers appearing on UE5 forums so I'll dig into this more.
No description
Phenakist
Phenakist4d ago
Yea I feel like it's got no way of setting other than the initialisation stage. So as an example for a runtime moving platform its this below: void AMovingPlatform::Tick(float DeltaTime) { // Pass to base Super::Tick(DeltaTime); FVector location = GetActorLocation(); location += FVector(15 * DeltaTime, 0, 0); // Update location based on DeltaTime SetActorLocation(location); } Looks like you could just take your existing NodeData.Location & PlayerLocation and use that as the same rules to calculate & update on a per tick basis to test functionality
Beef
BeefOP4d ago
thanks! I think I have enough to figure it out 🙂 :hypers: I appreciate it
Phenakist
Phenakist4d ago
let me know how it goes!
Beef
BeefOP2d ago
It turns out I'm a big dumb and there were at least a couple issues 1. My identifier from spawning wasn't propogating back to the struct I store it in so he was not properly finding the resource nodes to begin with :sadalpaca: . 2. I wasn't ensuring that I ignored self-raycasts, so when it did work everything was wonky, especially since there was a small chance it was moving a node from elsewhere on the map on top 😅
Want results from more Discord servers?
Add your server