Streaming::setModelAsNoLongerNeeded: Difference between revisions

From RAGE Multiplayer Wiki
No edit summary
 
Line 1: Line 1:
Unloads model from memory
{{ClientsideJsFunction}}
{{JSContainer|
 
==Function==
This function releases a specified model from memory. It’s helpful for optimizing memory usage, especially after spawning an entity using a model. After calling this, the game will no longer store the model in memory, freeing up resources.
 
==Syntax==
==Syntax==
<syntaxhighlight lang="javascript">mp.game.streaming.setModelAsNoLongerNeeded(model);</syntaxhighlight>
<syntaxhighlight lang="javascript">mp.game.streaming.setModelAsNoLongerNeeded(model);</syntaxhighlight>
=== Required Arguments ===
=== Required Arguments ===
*'''model:''' Model hash or name
*'''model:''' Model hash or name
===Return value===
===Return value===
*'''Undefined'''
*'''Undefined'''
==Example==
==Example==
<syntaxhighlight lang="javascript">
<syntaxhighlight lang="javascript">
// todo
// Load a model and create a ped, then release the model from memory
let model = mp.game.joaat("a_m_y_skater_01");
 
if (!mp.game.streaming.hasModelLoaded(model)) {
    mp.game.streaming.requestModel(model);
    while (!mp.game.streaming.hasModelLoaded(model)) mp.game.wait(0); // Wait until model is loaded
}
 
// Create a ped using the model
let playerPed = mp.peds.new(model, new mp.Vector3(0, 0, 0), 0);
 
// Release the model from memory after creating the ped
mp.game.streaming.setModelAsNoLongerNeeded(model);
</syntaxhighlight>
</syntaxhighlight>
}}
==See also==
==See also==
{{Streaming_functions_c}}
{{Streaming_functions_c}}
[[Category:Clientside API]]
[[Category:Clientside API]]
[[Category:TODO: Example]]
[[Category:TODO: Example]]

Latest revision as of 12:17, 2 November 2024

Client-Side
Function

 JavaScript



JavaScript Syntax


Function

This function releases a specified model from memory. It’s helpful for optimizing memory usage, especially after spawning an entity using a model. After calling this, the game will no longer store the model in memory, freeing up resources.

Syntax

mp.game.streaming.setModelAsNoLongerNeeded(model);

Required Arguments

  • model: Model hash or name

Return value

  • Undefined

Example

// Load a model and create a ped, then release the model from memory
let model = mp.game.joaat("a_m_y_skater_01");

if (!mp.game.streaming.hasModelLoaded(model)) {
    mp.game.streaming.requestModel(model);
    while (!mp.game.streaming.hasModelLoaded(model)) mp.game.wait(0); // Wait until model is loaded
}

// Create a ped using the model
let playerPed = mp.peds.new(model, new mp.Vector3(0, 0, 0), 0);

// Release the model from memory after creating the ped
mp.game.streaming.setModelAsNoLongerNeeded(model);



See also