I did it
Sorry, I only showed you the replication part. (I attached all code at the end)
I made a pool for sounds and a particle system as well (everything is reused).
Yes, they do absolutely nothing.
I made a subsystem to simulate the shots. Just place the projectile on the muzzle of the weapon. and then returns it to the pool.
All I do is enable and disable things.
There must be something I haven’t disabled, I think it’s something related to replication (NetBroadcastTicktime) but I’m not sure.
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
void AProjectile::Disable()
{
AAmmoBase::Disable();
if(!IsValid(Movement))
{
Message::Error("AProjectile::Disable --> Movement is NULL" );
return;
}
Movement->ProjectileGravityScale = 0.0f;
Movement->Velocity = FVector(0.0f, 0.0f, 0.0f);
Movement->Deactivate();
Movement->bAutoActivate=false;
if(!IsValid(NiagaraTrail))
{
Message::Error("AProjectile::Disable --> NiagaraTrail is NULL" );
return;
}
NiagaraTrail->Disable();
NiagaraTrail->Deactivate();
NiagaraTrail->bAutoActivate=false;
if(!IsValid(NiagaraProjectile))
{
Message::Error("AProjectile::Disable --> NiagaraProjectile is NULL" );
return;
}
NiagaraProjectile->Hide();
NiagaraProjectile->Disable();
NiagaraProjectile->Deactivate();
NiagaraProjectile->bAutoActivate=false;
if(!IsValid(HitNiagara_Explotion))
{
Message::Error("AProjectile::Disable --> HitNiagara_Explotion is NULL" );
return;
}
//HitNiagara_Explotion->Disable();
HitNiagara_Explotion->Deactivate();
HitNiagara_Explotion->bAutoActivate=false;
if(!IsValid(AudioShooting))
{
Message::Error("AProjectile::Disable --> AudioShooting is NULL" );
return;
}
AudioShooting->InitPooling();
AudioShooting->Deactivate();
AudioShooting->bAutoActivate=false;
if(!IsValid(Hit_Audio))
{
Message::Error("AProjectile::Disable --> Hit_Audio is NULL" );
return;
}
//Hit_Audio->InitPooling();
Hit_Audio->Deactivate();
Hit_Audio->bAutoActivate=false;
if(!IsValid(Damage_Component))
{
Message::Error("AProjectile::Disable --> Damage_Component is NULL" );
return;
}
Damage_Component->Deactivate();
Damage_Component->bAutoActivate=false;
if (!IsValid(SphereCollider))
{
Message::Error("Projectile::Disable --> SphereMesh is NULL");
return;
}
SphereCollider->SetNotifyRigidBodyCollision(false);
SphereCollider->SetGenerateOverlapEvents(false);
SphereCollider->SetCollisionEnabled( ECollisionEnabled::Type::NoCollision);
SphereCollider->Deactivate();
if (!IsValid(SphereMesh))
{
Message::Error("Projectile::Disable --> SphereMesh is NULL");
return;
}
SphereMesh->SetVisibility(false, false);
SphereMesh->Deactivate();
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
void AProjectile::Enable()
{
AAmmoBase::Enable();
if(!IsValid(Movement))
{
Message::Error("AProjectile::Enable --> Movement is NULL" );
return;
}
//Movement->InitialSpeed = 3000.0f;
//Movement->MaxSpeed = 3000.0f;
Movement->ProjectileGravityScale = GravityScale;
Movement->Activate();
if(!IsValid(NiagaraTrail))
{
Message::Error("AProjectile::Enable --> NiagaraTrail is NULL" );
return;
}
NiagaraTrail->Enable();
NiagaraTrail->Activate();
if(!IsValid(NiagaraProjectile))
{
Message::Error("AProjectile::Enable --> NiagaraProjectile is NULL" );
return;
}
NiagaraProjectile->Show();
NiagaraProjectile->Enable();
NiagaraProjectile->Activate();
if(!IsValid(HitNiagara_Explotion))
{
Message::Error("AProjectile::Enable --> HitNiagara_Explotion is NULL" );
return;
}
HitNiagara_Explotion->Activate();
if(!IsValid(AudioShooting))
{
Message::Error("AProjectile::Enable --> AudioShooting is NULL" );
return;
}
AudioShooting->Activate();
AudioShooting->Play();
if(!IsValid(Hit_Audio))
{
Message::Error("AProjectile::Enable --> Hit_Audio is NULL" );
return;
}
Hit_Audio->Activate();
//Hit_Audio->Play();
if(!IsValid(Damage_Component))
{
Message::Error("AProjectile::Enable --> Damage_Component is NULL" );
return;
}
Damage_Component->Activate();
if (!IsValid(SphereCollider))
{
Message::Error("AProjectile::Enable --> SphereMesh is NULL");
return;
}
SphereCollider->SetNotifyRigidBodyCollision(true);
SphereCollider->SetGenerateOverlapEvents(true);
SphereCollider->SetCollisionEnabled( ECollisionEnabled::Type::QueryAndPhysics);
SphereCollider->Activate();
if (!IsValid(SphereMesh))
{
Message::Error("AProjectile::Enable --> SphereMesh is NULL");
return;
}
SphereMesh->SetVisibility(true, false);
SphereMesh->Activate();
}