void UK2Node_GetArrayItem::PostReconstructNode()
{
	if (GetTargetArrayPin()->LinkedTo.Num() > 0)
	{
		PropagatePinType(GetTargetArrayPin()->LinkedTo[0]->PinType);
	}
	else if (GetResultPin()->LinkedTo.Num() > 0)
	{
		PropagatePinType(GetResultPin()->LinkedTo[0]->PinType);
	}
}
void UK2Node_CallArrayFunction::AllocateDefaultPins()
{
	Super::AllocateDefaultPins();

	const UEdGraphSchema_K2* Schema = GetDefault<UEdGraphSchema_K2>();

	UEdGraphPin* TargetArrayPin = GetTargetArrayPin();
	check(TargetArrayPin);
	TargetArrayPin->PinType.bIsArray = true;
	TargetArrayPin->PinType.bIsReference = true;
	TargetArrayPin->PinType.PinCategory = Schema->PC_Wildcard;
	TargetArrayPin->PinType.PinSubCategory = TEXT("");
	TargetArrayPin->PinType.PinSubCategoryObject = NULL;

	TArray< FArrayPropertyPinCombo > ArrayPins;
	GetArrayPins(ArrayPins);
	for(auto Iter = ArrayPins.CreateConstIterator(); Iter; ++Iter)
	{
		if(Iter->ArrayPropPin)
		{
			Iter->ArrayPropPin->bHidden = true;
			Iter->ArrayPropPin->bNotConnectable = true;
			Iter->ArrayPropPin->bDefaultValueIsReadOnly = true;
		}
	}

	PropagateArrayTypeInfo(TargetArrayPin);
}
void UK2Node_CallArrayFunction::PropagateArrayTypeInfo(const UEdGraphPin* SourcePin)
{
	if( SourcePin )
	{
		const UEdGraphSchema_K2* Schema = CastChecked<UEdGraphSchema_K2>(GetSchema());
		const FEdGraphPinType& SourcePinType = SourcePin->PinType;

		TArray<UEdGraphPin*> DependentPins;
		GetArrayTypeDependentPins(DependentPins);
		DependentPins.Add(GetTargetArrayPin());
	
		// Propagate pin type info (except for array info!) to pins with dependent types
		for (UEdGraphPin* CurrentPin : DependentPins)
		{
			if (CurrentPin != SourcePin)
			{
				CA_SUPPRESS(6011); // warning C6011: Dereferencing NULL pointer 'CurrentPin'.
				FEdGraphPinType& CurrentPinType = CurrentPin->PinType;

				bool const bHasTypeMismatch = (CurrentPinType.PinCategory != SourcePinType.PinCategory) ||
					(CurrentPinType.PinSubCategory != SourcePinType.PinSubCategory) ||
					(CurrentPinType.PinSubCategoryObject != SourcePinType.PinSubCategoryObject);

				if (!bHasTypeMismatch)
				{
					continue;
				}

				if (CurrentPin->SubPins.Num() > 0)
				{
					Schema->RecombinePin(CurrentPin->SubPins[0]);
				}

				CurrentPinType.PinCategory          = SourcePinType.PinCategory;
				CurrentPinType.PinSubCategory       = SourcePinType.PinSubCategory;
				CurrentPinType.PinSubCategoryObject = SourcePinType.PinSubCategoryObject;

				// Reset default values
				if (!Schema->IsPinDefaultValid(CurrentPin, CurrentPin->DefaultValue, CurrentPin->DefaultObject, CurrentPin->DefaultTextValue).IsEmpty())
				{
					CurrentPin->ResetDefaultValue();
				}
			}
		}
	}
}
void UK2Node_CallArrayFunction::NotifyPinConnectionListChanged(UEdGraphPin* Pin)
{
	Super::NotifyPinConnectionListChanged(Pin);

	TArray<UEdGraphPin*> PinsToCheck;
	GetArrayTypeDependentPins(PinsToCheck);

	for (int32 Index = 0; Index < PinsToCheck.Num(); ++Index)
	{
		UEdGraphPin* PinToCheck = PinsToCheck[Index];
		if (PinToCheck->SubPins.Num() > 0)
		{
			PinsToCheck.Append(PinToCheck->SubPins);
		}
	}

	PinsToCheck.Add(GetTargetArrayPin());

	if (PinsToCheck.Contains(Pin))
	{
		const UEdGraphSchema_K2* Schema = GetDefault<UEdGraphSchema_K2>();
		bool bNeedToPropagate = false;

		if( Pin->LinkedTo.Num() > 0 )
		{
			if (Pin->PinType.PinCategory == Schema->PC_Wildcard)
			{
				UEdGraphPin* LinkedTo = Pin->LinkedTo[0];
				check(LinkedTo);
				check(Pin->PinType.bIsArray == LinkedTo->PinType.bIsArray);

				Pin->PinType.PinCategory = LinkedTo->PinType.PinCategory;
				Pin->PinType.PinSubCategory = LinkedTo->PinType.PinSubCategory;
				Pin->PinType.PinSubCategoryObject = LinkedTo->PinType.PinSubCategoryObject;

				bNeedToPropagate = true;
			}
		}
		else
		{
			bNeedToPropagate = true;

			for (UEdGraphPin* PinToCheck : PinsToCheck)
			{
				if (PinToCheck->LinkedTo.Num() > 0)
				{
					bNeedToPropagate = false;
					break;
				}
			}

			if (bNeedToPropagate)
			{
				Pin->PinType.PinCategory = Schema->PC_Wildcard;
				Pin->PinType.PinSubCategory = TEXT("");
				Pin->PinType.PinSubCategoryObject = NULL;
			}
		}

		if (bNeedToPropagate)
		{
			PropagateArrayTypeInfo(Pin);
		}
	}
}