Jump to content

Unreal Engine How to stop playing sound which is executed every frame? (BOOL) C++?

TheNaitsyrk
Go to solution Solved by Beesman,

I hope i understood you correctly that want to play a sound once the character enters an area but only when he enters and your problem is it starts playing each frame he is in there.

Well you can check if he is beyond the position each time but only set some play sound bool when the crossing happens.

If you want to play the sound only if he just crossed and is in the area, there are many ways to do that.

Simple example that crossed my mind is to control his being in the area for the last frame and the current one.

 

fe. pseudo code example:

bool isInArea51(Player player){...} //...function that returns if he is in - if it's just some x boundry probably just x => ??..
void playArea51ThemeSong(){...} //...function that plays the sound (probably in another threat 
bool wasInArea51 = false;
//...
//...
//The block where your stuff you do each frame happens or the tick of the pawn or w/e
{
  //...
	If( isInArea51(player) &&  !wasInArea51)//he is in but wasn't here last frame
	{
		playArea51ThemeSong();//probably in another threat dunno if unreals sound playing stuff handles this for you
	}
  //...
	wasInArea51 = isInArea51(player);
}

This will work for re-entering the area and will not loop if you stand directly on the threshold.

 

Hi,

 

I have made code which literally play sound once an actor (aka character) crosses certain X (position) in the game. However, once he goes past it, the sound is executed every frame.

 

Code needs to be in the tick section of pawn.

 

I know I need to use bool but how do I formulate it? Help would be much appreciated. Thanks!

Main PC:

CPU: Intel Core i9 13900KS SP 116 (124P-102E) (6.1Ghz P-Cores 4.8Ghz E-cores) MC SP 88

CPU Voltage: LLC8 1.525V (real voltage 1.425V + - Temps 85-90 P-Cores, 70-73 E-cores)

Cooled by: Supercool Direct Die 14th gen full nickel

Motherboard: Z790 ASUS Maximus Apex Encore

RAM: GSkill TridentZ 2x24GB DDR5 8600Mhz CL38 (OC from 8000Mhz CL40)

GPU: RTX MSI 4090 Suprim X with EKWB waterblock

Case: My own case fabricated out of aluminium and wood

Storage: 4x 2TB Sarbent Rocket Plus Gen 4.0 NVMe, 1x External 2TB Seagate Barracuda (Backup)

WiFi: BE202 WiFi 7 Tri-Band card module

PSU: Corsair AX1600i with custom black and red cables with 2x Corsair 5V+ Load Balancer

Display: Samsung Oddysey G9 240Hz Ver. 5120x1440 with G-Sync and Freesync Premium Pro 1008 Firmware Ver, and 1x Electriq USB C 1080p 15'8 inch IPS portable display for temperature and stats, MSI 23'8 144Hz G-Sync

Fan Controllers:  6x AquaComputer Octo with 5 temperature sensors

Cooling: Three Custom Loops:

1st Loop: 5x 480mm XE CoolStream radiators with 1x Revo D5 RGB pump and 1x Rajintek Antila D5 Evo RGB pump for GPU only cooling with 2x Koolance QDC3, red coolant

2nd Loop: 5x 480mm XE CoolStream radiators with 1x Revo D5 RGB pump and 1x Rajintek Antila D5 Evo RGB pump for CPU only cooling with 2x Koolance QDC3, purple coolant

3rd Loop: 1x 240mm PE CoolStream radiator with 1x EKWB Revo D5 pump (RAM ONLY)

Total: 5x pumps and 13x radiators 50x 3000RPM Noctua Industrial fans

Keyboard: Razer BlackWidow V3 RGB - Green switches

Sound: Logitech Z680 5.1 THX Certified 505W Speakers

Mouse: Razer Basilisk Ultimate Wireless with charging dock

Piano: Yamaha P155

Phone: Oppo Find X5 Pro

Camera: Logitech Brio Pro 4K

VR: Oculus Rift S

External SSD: 256GB Overclocking OS

LaptopMSI Titan GT77HX V13RTX 4090 175W, i9 13980HX OC: P-Cores 5.8Ghz 3 cores and 5.2Ghz 5 cores and E-Cores 4.3Ghz, 192GB of RAM @5600Mhz @3600 (chipset limit),

12TB (3x4TB) of NVMe, 17'3 inch 4K 144Hz MiniLED screen, 4x 17'3 ASUS portable USB-C Monitors 240Hz, Creative Sound Blaster G6 Sound Card, Portable 16TB NVMe in TB4 enclosures (8x2TB), Razer Basilisk Ultimate Wireless with charging dock gaming mouse, Keychron K3 gaming keyboard with blue switches low profile, Logitech Brio 4K Webcam.

Hand held: ROG Ally with XG Mobile RTX 3080 with Keychron K3 low profile keyboard (Blue Switches) and Razer Hyperspeed V3 mouse and 4TB NVMe upgrade (WDBlack SN850X), with 100W 20000Mah power bank and portable monitor ROG XG17AHP 17'3 inch 240Hz with built in battery, and 518Wh Power station for Camping.

Link to comment
Share on other sites

Link to post
Share on other sites

make it so the play command gets executed if he passes a certain point and if a variable is false. also make sure when the software runs that variable is false

when its executed once the sound plays and the variable goes to true. so now it cant play anymore cause its true

when it passes from somewhare else you can make it so the variable goes back to false so if you pass again it will play the sound

Link to comment
Share on other sites

Link to post
Share on other sites

I hope i understood you correctly that want to play a sound once the character enters an area but only when he enters and your problem is it starts playing each frame he is in there.

Well you can check if he is beyond the position each time but only set some play sound bool when the crossing happens.

If you want to play the sound only if he just crossed and is in the area, there are many ways to do that.

Simple example that crossed my mind is to control his being in the area for the last frame and the current one.

 

fe. pseudo code example:

bool isInArea51(Player player){...} //...function that returns if he is in - if it's just some x boundry probably just x => ??..
void playArea51ThemeSong(){...} //...function that plays the sound (probably in another threat 
bool wasInArea51 = false;
//...
//...
//The block where your stuff you do each frame happens or the tick of the pawn or w/e
{
  //...
	If( isInArea51(player) &&  !wasInArea51)//he is in but wasn't here last frame
	{
		playArea51ThemeSong();//probably in another threat dunno if unreals sound playing stuff handles this for you
	}
  //...
	wasInArea51 = isInArea51(player);
}

This will work for re-entering the area and will not loop if you stand directly on the threshold.

 

Link to comment
Share on other sites

Link to post
Share on other sites

On 2017-5-22 at 7:28 PM, Beesman said:

I hope i understood you correctly that want to play a sound once the character enters an area but only when he enters and your problem is it starts playing each frame he is in there.

Well you can check if he is beyond the position each time but only set some play sound bool when the crossing happens.

If you want to play the sound only if he just crossed and is in the area, there are many ways to do that.

Simple example that crossed my mind is to control his being in the area for the last frame and the current one.

 

fe. pseudo code example:


bool isInArea51(Player player){...} //...function that returns if he is in - if it's just some x boundry probably just x => ??..
void playArea51ThemeSong(){...} //...function that plays the sound (probably in another threat 
bool wasInArea51 = false;
//...
//...
//The block where your stuff you do each frame happens or the tick of the pawn or w/e
{
  //...
	If( isInArea51(player) &&  !wasInArea51)//he is in but wasn't here last frame
	{
		playArea51ThemeSong();//probably in another threat dunno if unreals sound playing stuff handles this for you
	}
  //...
	wasInArea51 = isInArea51(player);
}

This will work for re-entering the area and will not loop if you stand directly on the threshold.

 

This helped, thank you!

Main PC:

CPU: Intel Core i9 13900KS SP 116 (124P-102E) (6.1Ghz P-Cores 4.8Ghz E-cores) MC SP 88

CPU Voltage: LLC8 1.525V (real voltage 1.425V + - Temps 85-90 P-Cores, 70-73 E-cores)

Cooled by: Supercool Direct Die 14th gen full nickel

Motherboard: Z790 ASUS Maximus Apex Encore

RAM: GSkill TridentZ 2x24GB DDR5 8600Mhz CL38 (OC from 8000Mhz CL40)

GPU: RTX MSI 4090 Suprim X with EKWB waterblock

Case: My own case fabricated out of aluminium and wood

Storage: 4x 2TB Sarbent Rocket Plus Gen 4.0 NVMe, 1x External 2TB Seagate Barracuda (Backup)

WiFi: BE202 WiFi 7 Tri-Band card module

PSU: Corsair AX1600i with custom black and red cables with 2x Corsair 5V+ Load Balancer

Display: Samsung Oddysey G9 240Hz Ver. 5120x1440 with G-Sync and Freesync Premium Pro 1008 Firmware Ver, and 1x Electriq USB C 1080p 15'8 inch IPS portable display for temperature and stats, MSI 23'8 144Hz G-Sync

Fan Controllers:  6x AquaComputer Octo with 5 temperature sensors

Cooling: Three Custom Loops:

1st Loop: 5x 480mm XE CoolStream radiators with 1x Revo D5 RGB pump and 1x Rajintek Antila D5 Evo RGB pump for GPU only cooling with 2x Koolance QDC3, red coolant

2nd Loop: 5x 480mm XE CoolStream radiators with 1x Revo D5 RGB pump and 1x Rajintek Antila D5 Evo RGB pump for CPU only cooling with 2x Koolance QDC3, purple coolant

3rd Loop: 1x 240mm PE CoolStream radiator with 1x EKWB Revo D5 pump (RAM ONLY)

Total: 5x pumps and 13x radiators 50x 3000RPM Noctua Industrial fans

Keyboard: Razer BlackWidow V3 RGB - Green switches

Sound: Logitech Z680 5.1 THX Certified 505W Speakers

Mouse: Razer Basilisk Ultimate Wireless with charging dock

Piano: Yamaha P155

Phone: Oppo Find X5 Pro

Camera: Logitech Brio Pro 4K

VR: Oculus Rift S

External SSD: 256GB Overclocking OS

LaptopMSI Titan GT77HX V13RTX 4090 175W, i9 13980HX OC: P-Cores 5.8Ghz 3 cores and 5.2Ghz 5 cores and E-Cores 4.3Ghz, 192GB of RAM @5600Mhz @3600 (chipset limit),

12TB (3x4TB) of NVMe, 17'3 inch 4K 144Hz MiniLED screen, 4x 17'3 ASUS portable USB-C Monitors 240Hz, Creative Sound Blaster G6 Sound Card, Portable 16TB NVMe in TB4 enclosures (8x2TB), Razer Basilisk Ultimate Wireless with charging dock gaming mouse, Keychron K3 gaming keyboard with blue switches low profile, Logitech Brio 4K Webcam.

Hand held: ROG Ally with XG Mobile RTX 3080 with Keychron K3 low profile keyboard (Blue Switches) and Razer Hyperspeed V3 mouse and 4TB NVMe upgrade (WDBlack SN850X), with 100W 20000Mah power bank and portable monitor ROG XG17AHP 17'3 inch 240Hz with built in battery, and 518Wh Power station for Camping.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×