iniside
(iniside)
May 1, 2014, 3:49pm
1
I’m trying to spawn actor in game. For testing it is very simple:
HitLocation.ImpactPoint.Z += Height;
FTransform SpawnTM(FRotator(0, 0, 0), HitLocation.ImpactPoint);
ARPGProjectileSpawner* spawner = Cast<ARPGProjectileSpawner>(UGameplayStatics::BeginSpawningActorFromClass(PowerOwner, effectActor, SpawnTM));
if (spawner)
{
spawner->SetActorLocation(HitLocation.ImpactPoint);
spawner->SetActorRelativeLocation(HitLocation.ImpactPoint);
UGameplayStatics::FinishSpawningActor(spawner, SpawnTM);
}
}
It works, and actor spawn in correct position.
No in that spawned actor I try to get location:
FVector currentLocation = GetActorLocation();
DrawDebugSphere((), currentLocation, Radius, 32, FColor::Yellow, false, 10.0f);
And GetActorLocation() return 0 vector.
Rama
(Rama)
May 1, 2014, 3:53pm
2
#Regular SpawnActor?
For comparison, what happens if you use regular ole’ SpawnActor?
FActorSpawnParameters SpawnInfo;
SpawnInfo.bNoCollisionFail = true;
SpawnInfo.Owner = this;
SpawnInfo.Instigator = NULL;
SpawnInfo.bDeferConstruction = false;
return ()->SpawnActor<ARPGProjectileSpawner>(PowerOwner, HitLocation.ImpactPoint ,FRotator::ZeroRotator, SpawnInfo );
Why are you using both SetActorLocation and SetActorRelativelocation in same time? Also ahy don’t you use ()->SpawnActor() to spawn?
iniside
(iniside)
May 1, 2014, 4:04pm
4
The issue with SpawnActor is, it can’t spawn Actor from TSubclassOf actor.
And I have some parts of my actor defined in blueprint.
iniside
(iniside)
May 1, 2014, 4:30pm
5
Ah nvm, my previous comment, It take SubclassOf.
But the issue is, I need to spawn actor in Level, and when using SpawnActor, mesh I added to blueprint, doesn’t spawn.
But even if, the location vector is still 0.
Rama
(Rama)
May 1, 2014, 4:41pm
6
I am not sure
but if you want to spawn a BP version of a base class
you should check out my templated spawn code
#Templated Spawn BP Wiki
After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — ue4community.wiki! You will be able to find content from the official...
Reading time: 1 mins 🕑
Likes: 14 ❤
iniside
(iniside)
May 1, 2014, 5:02pm
7
The BP spawned, but the issue of wrong location remained. It still spawn in 0,0,0 location.
Hmmm this could be related to root component :> again why call setactrorelativelocation?
iniside
(iniside)
May 1, 2014, 7:06pm
9
The issue was that I called even in wrong function, and it was called before location has been set.
It should have been called in OnConstruction.