So the issue i’m having is that, either spawning an actor through blueprint or c++, is not appearing visible through the players camera nor if i play as standalone game. However it appears in editor viewport.
As i thought it might have to do with my project and a deeper problem that i was not able to see, i tried to replicate the problem yet again on a clean project, and the problem persists.
Here is how i replicate it for c++:
MyActor.h
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "MyActor.generated.h"
UCLASS()
class CPPTESTING_API AMyActor : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
AMyActor();
UFUNCTION(BlueprintCallable, Category = "Something")
bool TestingSpawn();
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Something")
AActor * TestActor;
};
MyActor.cpp
#include "MyActor.h"
#include "Engine/World.h"
// Sets default values
AMyActor::AMyActor()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
}
bool AMyActor::TestingSpawn()
{
UWorld * World = GetWorld();
if (!World) return false;
FActorSpawnParameters SpawnParams;
SpawnParams.Owner = this;
SpawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
AActor * SpawnedObj = World->SpawnActor<AActor>(TestActor->GetClass(), FVector(0, 0, 0), FRotator(0, 0, 0), SpawnParams);
return true;
}
Then I need to set an actor to my TestActor. I decided to set it through the editor like so:
1)Place a BP version of MyActor on level
2)Create a BP of an actor with a static mesh component (can be anything, i chose the default engine Cube) and make sure it’s movable. Let’s call this SomethingActor.
-
Place SomethingActor in the same level as MyActorBP.
-
Now you can add SomethingActor to the TestActor in MyActorBP.
For the blueprint case, just create two actors, one being the one that spawns and the one that is the class you want to spawn.
Happens the same.
You might notice that i also have a custom GameModeBase and a Pawn, that was to make it easier to check the camera freely through my pawn.
I have been trying to solve this all day and i just don’t know if it’s me that i’m missing a step somewhere or is it rly a rendering bug.
Thank you for your time,
KittyT