Call constructor issue

hi all,

have 2 files. fireball and GameCharacter and need i make a fireball in gameCharacter and call function on this .
GameCharecter.cpp :

void AGameCharacter::LaunchSpell()
{
	AS_Fireball * test = NewObject<class AS_Fireball>();
	test->LaunchProjectile(this->GetActorLocation() , this->GetActorRotation() );
}

and a basic constructor in fireball.cpp :

AS_Fireball::AS_Fireball(const class FPostConstructInitializeProperties& PCIP)
	: Super(PCIP)
{
	
}

this crash my editor, shoud dont be the right way ?

Your fireball is an Actor, the NewObject<>() is for UObjects.
Use Spawn() instead.

thanks but i just need to have a firball to use function on fireball.cpp, i dont need to spawn him in the world

But you have to spawn an actor to use it, if you just need a function from that actor you can check if the DefaultObject is enough for your needs.

i use spawn() in fireball.cpp to make him in the world. i just need a reference to him to call this function

i fnish to resolve my probleme. i use :

AS_Fireball * test = (AS_Fireball*)GetWorld()->SpawnActor(AS_Fireball::StaticClass());

with no location precised to dont see him in the world

i have a character who can use spell
so i have spell.cpp |
projectileSpell : spell |
fireball: projectileSpell

but the character can change spell anyway.
all spell will be override by BP ti implement visual effect better
so when i spawn a spell, i spawn a BP .
and its a the launch() function in fireball.cpp will make the BP

You can’t have a reference of an nonexistant object. :wink:

It simply get spawned at 0,0,0 :wink:
But onestly, if you need a reference to a not needed actor, maybe there’s something wrong about your program structure.
What are you trying to achieve?

Aren’t you overshooting it?
You can easily customize it directly in C++, right after spawning, writing down a couple of function as you need: for example, one to change the mesh.

i use BP to make the visual , add dynamic materail , particule emiter and more