Announcement

Collapse
No announcement yet.

Problem about port from C++ to BP

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Problem about port from C++ to BP

    I using the code from the Shooter Demo as reference to make a thing in Blueprints, but i got a problem here:

    Code:
    void AShooterCharacter::SpawnDefaultInventory()
    {
    	if (Role < ROLE_Authority)
    	{
    		return;
    	}
    
    	int32 NumWeaponClasses = DefaultInventoryClasses.Num();	
    	for (int32 i = 0; i < NumWeaponClasses; i++)
    	{
    		if (DefaultInventoryClasses[i])
    		{
    			FActorSpawnParameters SpawnInfo;
    			SpawnInfo.bNoCollisionFail = true;
    			AShooterWeapon* NewWeapon = GetWorld()->SpawnActor<AShooterWeapon>(DefaultInventoryClasses[i], SpawnInfo);
    			AddWeapon(NewWeapon);
    		}
    	}
    ...
    
    void AShooterCharacter::AddWeapon(AShooterWeapon* Weapon)
    {
    	if (Weapon && Role == ROLE_Authority)
    	{
    		Weapon->OnEnterInventory(this);
    		Inventory.AddUnique(Weapon);
    	}
    }
    Code:
    	/** default inventory list */
    	UPROPERTY(EditDefaultsOnly, Category=Inventory)
    	TArray<TSubclassOf<class AShooterWeapon> > DefaultInventoryClasses;
    
    	/** weapons in inventory */
    	UPROPERTY(Transient, Replicated)
    	TArray<class AShooterWeapon*> Inventory;
    
    	/** currently equipped weapon */
    	UPROPERTY(Transient, ReplicatedUsing=OnRep_CurrentWeapon)
    	class AShooterWeapon* CurrentWeapon;


    This is what i got now:


    *Clear BP


    Then i got problems with that lines:
    Code:
    FActorSpawnParameters SpawnInfo;
    SpawnInfo.bNoCollisionFail = true;
    AShooterWeapon* NewWeapon = GetWorld()->SpawnActor<AShooterWeapon>(DefaultInventoryClasses[i], SpawnInfo);
    My problem is how manage the spawn or how make that like in the C++ code.
    How or for what i give the index of DefaultInventoryClasses[i] ?? and how made that in BP ?
    Can some one give me an example of this or what is bad ? if is possible with a screen of the configuration in BP.
    Last edited by Hevedy; 04-28-2015, 06:12 AM.
    Hevedy - Instance Tools: https://hevedy.itch.io/hevedyinstances
    Hevedy - Image Tools: https://hevedy.itch.io/imagetools

    #2
    I've already recreated this in Blueprint so I should be able to help you out. You mostly have it right, I'm not at home but I can upload screenshots when I'm there.

    GetWorld is your characters World Transform, so Get Player Character---> Get World Transform. Then it takes that transform and feeds it into the Spawn Actor ForEach weapon in DefaultInventoryClasses[Class array index]. Then it adds each weapon to Inventory Actor Array(Object Array).

    The [i] just represents the current index it is on in the for loop, starting with 0. ForEach when i < Number of weapons do spawn actor DefaultInventory[i], add weapon

    AddWeapon calls OnEnterInventory from the weapon blueprint which sets the owner, then it adds unique to your Inventory Actor Array.

    EquipWeapon sets your current weapon variable then calls OnEquip from the weapon, which runs attachmeshtopawn()
    Last edited by DEDRICK; 04-28-2015, 11:28 AM.

    Comment

    Working...
    X