Download

2 identical code one returns Reference and other do not ? making me go crazy !!

code 1 :



AActor* actor = pawn->GetWorld()->SpawnActor<AActor>(ability->BotAbilityContent[AbilityIndex].AbilityBluePrintClass, pawn->GetWeaponTransform());
	if (IsValid(primitiveComp) && IsValid(actor)) 
	{
	Cast<AProjectile>(actor)->SetPrimitiveComp(primitiveComp);
	//set teh next path node
	Cast<AProjectile>(actor)->SetNodeActor(pawn->NextPathNode);
	}


Code 1 I get the Spawn actor’s reference and everything is fine

Code 2 :



	AActor* newActor =	pawn->GetWorld()->SpawnActor<AActor>(ability->BotAbilityContent[AbilityIndex].AbilityBluePrintClass, GetTransformforIndex(pawn,i));
		
	if (IsValid(newActor))
	Cast<AProjectile>(newActor)->SetReferenceActor(pawn->GetOwner());



Code 2 i get null reference for the actor that had just spawned in the world ? weird :S help me out please.

More likely spawning failed due to e.g. collision issue and thus a null pointer is returned or some other error we do not have enough information to diagnose. You can specify a different collision handling method.

True !!! it was collision issues. Thanks RotemS it was really helpful :slight_smile: