Hi I there way to get pointer to actor position? I need to add a FVector pointer to std::vector, but I don’t know how. I Can’t do this by AActor::GetActorLocation(), It doesn’t return pointer.
It is my code:
I am obviously VERY late to offer a solution, but maybe you’ll appreciate advice.
I don’t understand exactly what you are asking for but I’ll offer knowledge that I think will help. I might include things that you already know. Disregard as necessary.
Getting a pointer to anything
To get a pointer to something, declare a variable for a pointer to that objects type. You can then use the address operator & to store the address of the object you want in the pointer variable you just declared. Heres a simple code example.
AActor* myActor = GetWorld()-><...>SpawnActor(...). // Just so I have an actor for this example
FVector myLocation = myActor->GetActorLocation(); // Declaring, Instantiating, and Initializing
// To get a refence to this vector, I just use the "&" operator
FVector* myLocationPtr = &myLocation;
Adding a std::vector and an FVector
Unless std:vector or FVector have functions that do this for you (I don’t think they do), you will need to do this manually. You can do this as follows
This is pretty straightforward. Many container objects (like a vector) can use the subscript operator [ ] to access elements directly.
std::vector<float> stdVector= {2.0, 3.2, 1.0};
FVector uVector(1.0, 2.0 1.3);
for (int i = 0; i < 3; i++){
uVector[i] += stdVector[i]; // add the elements of stdVector to that of uVector.
}
Changing the location of the actor
Your choice of words “I need to add a FVector pointer to std::vector…”, suggests that you might not be understanding what a pointer is. A pointer isn’t an object type, it’s the memory address that an object is stored at. If you want to add two things, be them std::vector or FVector, you NEVER add their pointers. You need to use the *dereferencing operating * * to get the object a pointer is pointing to.
I hope that this helps. My apologies if you know all of this already. If you see this at some point, good luck with future projects.
Is there any real harm in using std containers? I realize that UE provides alternatives, but if an std container provides a benefit is there any real reason not to use it? If so, what is the harm?
My guess is that is messes with UE4’s garbage collection. A standard container would probably normally need the programmer to do their own memory management.
I bet you that TArray and TSet are actually abstractions using the std containers. Just a guess though.
Storing pointer to an Actor location is not possible because it is a private member. If you want to know Actor coordinates in debug mode w/o calling GetActorLocation(), you may use pointer to a member of its UStaticMeshComponent: (((USceneComponent)&(((UPrimitiveComponent)&(((UMeshComponent)Mesh)))))).RelativeLocation