I was making a pointer to one of my class headers, and it says that the function is inaccessible, while I certainly think it is not. I am new to UE4 and C++ so this is probably a big derp, but I am stuck with this for a few hours now.
FPSCharacter class where is try to use the funtion InitVelocity:
// Spawn the fireball at the FireballLocation
AFPSProjectile* const Projectile = World->SpawnActor<AFPSProjectile>(ProjectileClass, FireballLocation, FireballRotation, SpawnParams);
if (Projectile)
{
// Find the launch directions
FVector const LaunchDir = FireballRotation.Vector();
Projectile->InitVelocity(LaunchDir);
}
And this is the projectile header:
// Fill out your copyright notice in the Description page of Project Settings.
And this is in the class FPSProjectile with the funtion InitVelocity declaration IN IT (Hahah, get it? :P).
void AFPSProjectile::InitVelocity(const FVector &ShootDirection)
{
if (ProjectileMovement)
{
// Sets the projectile's velocity to the desired direction
ProjectileMovement->Velocity = ShootDirection * ProjectileMovement->InitialSpeed;
}
}
Which version of the engine are you working in? Also, when you say that the function is inaccessable what is the exact error message you receive when it tries to call the function? If you could describe the behavior that you’re getting it will help determine what the cause of the problem is.
Hello ,
Thanks for the reply!
I am using engine version 4.6 (Because of a mouse glitch when I try to edit values inside the editor) and the excact error is:
Error 12 error C2248: 'AFPSProjectile::InitVelocity' : cannot access private member declared in class 'AFPSProjectile' C:\Users\Mats\Documents\Unreal Projects\FPSProject 4.6\Source\FPSProject\FPSCharacter.cpp 111 1 FPSProject
There was a code change in 4.6 that changed the line from GENERATED_UCLASS_BODY() to GENERATED_BODY(). The assumed specifier with the update is private however the assumed specifier with the older version (UCLASS) was public, thus why it wasn’t explicitly needed. Stating whether something is public, private, or protected will generally make it easier to follow the flow of the programming overall.
I have the same problem.I’m using a TArray(TArray is type of MyClass)
nothing is out of ordinary.All variables and Methods are public.but i still get the error C2248: ‘MyClass::MyClass’ : cannot access private member declared in class ‘MyClass’.
I’m using Unreal 4.9
can anyone please help me?!
I’m not sure I understand what you mean by the TArray is type of MyClass. Can you post the class files(.h and .cpp) for the class that is throwing this error?