By assigning something in the manner of MyMesh=OldMesh, you don't create a clone of a mesh. It's just a reference/pointer to the original object.
Destroying OldMesh will set MyMesh to none when OldMesh gets garbage collected.
If you set something on MyMesh, OldMesh has the same value.
==> It's still the same Object.
So you can assign any, in the defaultproperties, created objects to a variable and use it in the code.
Code:
class MyActor1 extends Actor;
// used for reference to the component
var StaticMeshComponent MyComp1;
event PostBeginPlay()
{
super.PostBeginPlay();
MyComp1.SetTranslation(vect(10,10,10));
}
defaultproperties
{
Begin Object class=StaticMeshComponent name=StaticMeshComponent1
StaticMesh=StaticMesh 'MSDG_Package.Models.myBox'
End Object
Components.Add(StaticMeshComponent1)
// Set the var
MyComp1=StaticMeshComponent1
}
Another approach
Code:
class MyActor1 extends Actor;
event PostBeginPlay()
{
local StaticMeshComponent TempComp;
super.PostBeginPlay();
foreach ComponentList(class'StaticMeshComponent', TempComp) {
// @TODO check if name is automacally set to NAME_X format
// temporally compare the prefix name
if (Left(TempComp.Name, 6) ~= "MyMesh") {
TempComp.SetTranslation(vect(10,10,10));
}
}
}
defaultproperties
{
Begin Object class=StaticMeshComponent name=StaticMeshComponent1
StaticMesh=StaticMesh 'MSDG_Package.Models.myBox'
End Object
Components.Add(StaticMeshComponent1)
}
Complete dynamically:
Code:
class MyActor extends Actor;
var StaticMeshComponent MyComp;
event PostBeginPlay()
{
local StaticMesh sm;
super.PostBeginPlay();
MyComp = new(self,"MyMesh") class'StaticMeshComponent';
sm = StaticMesh(DynamicLoadObject("MSDG_Package.Models.myBox", class'StaticMesh'));
MyComp.SetStaticMesh(sm);
MyComp.SetTranslation(vect(10,10,10));
AttachComponent(MyComp);
}
defaultproperties
{
}
Hope, it helps.
Bookmarks