Hi,
I have 2 classes in c++. There is a controller which spawns the second class/object.
Both are actor classes. I spawn it with:
LOCATION is set to 0 0 2000
AObjectSpawn* obj = GetWorld()->SpawnActor(spawnedObject,LOCATION,FRotator::ZeroRotator)
The object itself has this in it’s Tick function:
FString ds_string = GetActorLocation().ToString();
UE_LOG(LogTemp,Log,TEXT(“Logging %s”),*ds_string);
I added a cube to the object in the blueprints and activated gravity.
What happens: It spawns at 0 0 2000 and falls down to earth but logging is always its starting value 0 0 2000.
How to get the current value, which should be decreasing z?
My guess is that the Actor is staying at [0,0,2000], but the visual component is moving in the actor. Try getting the world location of that specific component instead of the actor location.
Thanks,
but how is it possible to have the actor position == object position? Did I mess up any gravity settings?
it worked for a cone in a tutorial but i can not find it again sadly
I’m pretty sure if you set your moving object as the root component of the actor, then the Actor transform will be the component’s transform. You’ll want to double check that for yourself though, I’m not 100% sure that’s correct, and I can’t test it at the moment.
So what a saw so far: if I enable physics only the “visible” part moves, I am unable to change its position with SetActorLocation.
But if it is disabled I can get the real visible value and change it. Is it not possible to change physical objects?
Hi, sorry for my late reply, i had no chance viewing the unreal engine.
So my Controller is “Spawning_Ball_Controller” and my object is BP_FloatingActor_Object.
It is included in the header file of the controller with:
UPROPERTY(EditAnyhwere, Category = “My Spawning Object”)
TSubclassOf spawnedObject;
He wanted to know the hierarchy in the spawned component, not in the spawner.
I would assume he is on the right track. What I think is going on, that in the Actor object which is being spawned, the root component is an empty scene component. You add an object - a box - as a component to the object, but it might not be the root which dictates the actor’s location. The box component will fall, and its location is updating, but because the scene component is not moving anywhere, the actors location stays the same.
My idea was to have an easy ‘controller → object’ structure, later for pawns, which can be controlled by the controller every tick, because the input is coming from an outside application.
I’m writing all in c++ to keep it dynamic since the input will arrive at the c++ part aswell.
Do you have any particular use for the “DefaultSceneRoot” component in the BP_FloatingActor_Object? If not, drag StaticMesh on top of it to make the StaticMesh as the actor’s root (and hence its position becomes the actor’s position), which may fix your position logging issues.
Otherwise, you should log the StaticMesh component’s location rather than the actor’s location.