Hey! I am having a few problems with my inventory system. I need to get the value of the number key that the player inputs. Anyone know how this works in UE4? I was also wondering how to get all the ActorSpawnParameters for UWorld::SpawnActor. Anyone know what I am missing? I cant really understand it from the API.
void AFPSCharacter::SwitchWeapon()
{
INT32 pressedKey;
for (FInventoryItem& wp : Items)
{
//Find what weapon is being selected....
if (pressedKey == wp.wpCollumn)
{
if (CurRow == wp.wpRow)
{
if (wp.isUnlocked)
{
if (!wp.hasBeenInstantiated)
{
wp.CurWeaponClass = UWorld::SpawnActor(wp.WeaponBlueprint, wpSpawnRot, wpSpawnPos);
wp.CurWeaponClass->Equip();
}
else
{
wp.CurWeaponClass->Equip();
}
}
}
}
}
}
Not entirely sure whether you would have to write your own functionality to find the key pressed:
int GetWeaponSwitchKey()
{
if (GetOwningPlayerController()->WasInputKeyJustPressed(EKeys::One)
return 0;
if (GetOwningPlayerController()->WasInputKeyJustPressed(EKeys::Two)
return 1;
...
}
Or you could look into GetOwningPlayerController()->InputKey() and maybe try to replicate what that function does but instead of taking an EKey, you return the key that is currently down.
Wow, that seems VERY time consuming, but i guess i could do that. I had another question with this answer though. The console tells me that “GetOwningPlayerController()” is not defined. How can I change that?
Ah right, that code was from one of my pawns that has a playercontroller using it. Might be able to use “Cast(GetWorld()->GetFirstPlayerController());” instead?
Anybody else have any suggestions or would like to add to what has been said? This would REALLY help me in my development progress and be much appreciated…thank you in advance!