Hi,
new on UE5 learning something new … also a bloody c++ beginner
created an actorcomponent.
it should generate subcomponents of itself until some conditions are met.
CustomComponent.h
#pragma once
#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "Engine.h"
#include "CustomComponent.generated.h"
UCLASS()
class PROGRAM_API UCustomComponent : public UActorComponent
{
GENERATED_BODY()
public:
UCustomComponent();
UCustomComponent(int arg_index, FVector arg_position, float arg_size);
int index;
FVector position;
float size;
TArray<UCustomComponent*> SubObjectArray;
void GenerateSubComponents();
protected:
private:
};
CustomComponent.cpp
#include "CustomComponent.h"
UCustomComponent::UCustomComponent()
{
}
UCustomComponent::UCustomComponent(int arg_index, FVector arg_position, float arg_size)
{
index = arg_index;
position = arg_position;
size = arg_size;
}
void UCustomComponent::GenerateSubComponents()
{
// some code ...
// do something with index, position and size ...
if (something_is_true)
{
break;
} else
{
SubObjectArray.SetNum(3);
SubObjectArray[0] = UCustomComponent*(0, FVector(0.0f, 0.0f, 0.0f), 1.0f);
SubObjectArray[1] = UCustomComponent*(1, FVector(1.0f, 1.0f, 1.0f), 2.0f);
SubObjectArray[2] = UCustomComponent*(2, FVector(2.0f, 2.0f, 2.0f), 3.0f);
for (UCustomComponent* child : SubObjectArray)
{
child->GenerateSubComponents();
}
}
}
everything builds fine expect:
SubObjectArray[0] = UCustomComponent*(0, FVector(0.0f, 0.0f, 0.0f), 1.0f);
SubObjectArray[1] = UCustomComponent*(1, FVector(1.0f, 1.0f, 1.0f), 2.0f);
SubObjectArray[2] = UCustomComponent*(2, FVector(2.0f, 2.0f, 2.0f), 3.0f);
VisdualStudio Error:
error C2275: 'UCustomComponent': illegal use of this type as an expression
if stumbled across NewObject but i don´t get how i should pass parameters to it, so the array holds the instanced object with it´s custom parameters…
again this woould be necessary because SubObjectArray is used for stuff in other functions, too, as soon as every objectinstances ares generated and stored …
need some advice since i´m stuck with this for some time now.
Thanks for your time