How UE5 loads the resources inside through the folder path under Content

prerequisite

Confirm that the resources will be packaged together into the package file.
If they cannot be packaged into the package file, you need to add an additional package directory in the project settings.
insert image description here

Two ways to get resource information by path

Blueprint (simple)

insert image description here

c++ (slightly complicated)

  1. Add dependent modules
    insert image description here

  2. Add reference path
    insert image description here

  3. Load resource information (TArray)
    insert image description hereinsert image description here

  4. The blueprint call and set
    insert image description here
    the FunLib_GetStaticMeshByContentPath method is actually a method of loading static resources on the c++ side by inputting the file path

// TEXT("/Game/StarterContent/Shapes/Shape_Cylinder.Shape_Cylinder")
bool UJGF_FunLib::FunLib_GetStaticMeshByContentPath( const FString& contentPath, UStaticMesh* & mesh)
{
    
    
	mesh = LoadObject<UStaticMesh>(nullptr, *contentPath);
	if (mesh)
	{
    
    
		return true;
	}
	return false;
}

Guess you like

Origin blog.csdn.net/tianxiaojie_blog/article/details/128686900