LogNetPackageMap: Warning: FNetGUIDCache::SupportsObject:…
- User
LogNetPackageMap: Warning: FNetGUIDCache::SupportsObject: GameplayAbilityPayloadComponent /Engine/Transient.GameplayAbilityPayloadComponent_29 NOT Supported. Can you show me c++ code
- Assistant
It seems like you're looking for help with adding network support for a gameplay ability payload component in Unreal Engine. I cannot provide an exact code because it depends on your specific use case and implementation. However, I can guide you on the general process, which involves adding network replication support for your component and properties.
- User
this is my class // Copyright 2022 Sabre Dart Studios
#include "GameplayAbilityPayloadComponent.h" #include <GameplayAbilityPayloadData.h> #include <Net/UnrealNetwork.h>
// Sets default values for this component's properties UGameplayAbilityPayloadComponent::UGameplayAbilityPayloadComponent() {
PrimaryComponentTick.bCanEverTick = false; //bReplicates = true;}
void UGameplayAbilityPayloadComponent::SetGameplayAbilityPayloadData(FGameplayAbilityPayloadData NewData) { GameplayAbilityPayloadData = NewData; }
FGameplayAbilityPayloadData UGameplayAbilityPayloadComponent::GetGameplayAbilityPayloadData() { return GameplayAbilityPayloadData; }
void UGameplayAbilityPayloadComponent::GetLifetimeReplicatedProps(TArray& OutLifetimeProps) const { Super::GetLifetimeReplicatedProps(OutLifetimeProps); DOREPLIFETIME(UGameplayAbilityPayloadComponent, GameplayAbilityPayloadData); }
void UGameplayAbilityPayloadComponent::OnRep_GameplayAbilityPayloadData() { } anything i am missing in terms of replication?
- Assistant
It seems like you have replicated the
GameplayAbilityPayloadDataproperty correctly, and you have implemented theOnRep_GameplayAbilityPayloadData()function. However, you need to denoteGameplayAbilityPayloadDatawith theUPROPERTYmacro to enable the replication and bind theOnRep_GameplayAbilityPayloadDatafunction to it.In your class header file (GameplayAbilityPayloadComponent.h), update the declaration of the
GameplayAbilityPayloadDataproperty:UCLASS(Blueprintable, ClassGroup=(Custom), meta=(BlueprintSpawnableComponent)) class YOUR_PROJECT_API UGameplayAbilityPayloadComponent : public UActorComponent { GENERATED_BODY() // Other properties and methods. protected: UPROPERTY(ReplicatedUsing = OnRep_GameplayAbilityPayloadData) FGameplayAbilityPayloadData GameplayAbilityPayloadData; UFUNCTION() void OnRep_GameplayAbilityPayloadData(); // Other properties and methods. }; - User
// Copyright 2022 Sabre Dart Studios
#pragma once
#include "CoreMinimal.h" #include "Components/ActorComponent.h" #include "GameplayAbilityPayloadData.h" #include "GameplayAbilityPayloadComponent.generated.h"
struct FGameplayAbilityPayloadData;
UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) ) class OPENWORLDSTARTER_API UGameplayAbilityPayloadComponent : public UActorComponent { GENERATED_BODY()
public: // Sets default values for this component's properties UGameplayAbilityPayloadComponent(); // Function to set UObject data UFUNCTION() void SetGameplayAbilityPayloadData(FGameplayAbilityPayloadData NewData);
// Function to get UObject data UFUNCTION() FGameplayAbilityPayloadData GetGameplayAbilityPayloadData();protected: virtual void GetLifetimeReplicatedProps(TArray& OutLifetimeProps) const override;
private: UPROPERTY(Replicated, ReplicatedUsing = OnRep_GameplayAbilityPayloadData) FGameplayAbilityPayloadData GameplayAbilityPayloadData; UFUNCTION() void OnRep_GameplayAbilityPayloadData(); }; this is my header class. Everything looks good in terms of replication?
- Assistant
Your header class looks almost good in terms of replication, but you need to make a small change.
The
GameplayAbilityPayloadDataproperty should be defined with both theReplicatedandReplicatedUsingattributes within theUPROPERTYmacro, like this:UPROPERTY(Replicated, ReplicatedUsing = OnRep_GameplayAbilityPayloadData) FGameplayAbilityPayloadData GameplayAbilityPayloadData;Update your header file with this change:
// Copyright 2022 Sabre Dart Studios #pragma once #include "CoreMinimal.h" #include "Components/ActorComponent.h" #include "GameplayAbilityPayloadData.h" #include "GameplayAbilityPayloadComponent.generated.h" struct FGameplayAbilityPayloadData; UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) ) class OPENWORLDSTARTER_API UGameplayAbilityPayloadComponent : public UActorComponent { GENERATED_BODY() public: // Sets default values for this component's properties UGameplayAbilityPayloadComponent(); // Function to set UObject data UFUNCTION() void SetGameplayAbilityPayloadData(FGameplayAbilityPayloadData NewData); // Function to get UObject data UFUNCTION() FGameplayAbilityPayloadData GetGameplayAbilityPayloadData(); protected: virtual void GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const override; private: UPROPERTY(Replicated, ReplicatedUsing = OnRep_GameplayAbilityPayloadData) FGameplayAbilityPayloadData GameplayAbilityPayloadData; UFUNCTION() void OnRep_GameplayAbilityPayloadData(); }; - User
How should I create the UGameplayAbilityPayloadComponent class?
- Assistant
To create the
UGameplayAbilityPayloadComponentclass in Unreal Engine, you should follow these steps:-
In your project's file explorer or Unreal Engine's Content Browser, navigate to your project's Source folder. Inside that folder, find the folder that corresponds to your project's name (e.g., MyProjectName). If you don't have a folder named "Components" or similar, create one.
-
Right-click inside that folder and choose
New C++ Class.
-
- User
I meant like to create the object. I am using UGameplayAbilityPayloadComponent* PayloadComponent = NewObject();
- Assistant
Apologies for the confusion. Your code to create a new instance of
UGameplayAbilityPayloadComponentis correct. UsingNewObject<>()is the right way to create UObject-derived classes in Unreal Engine.Here's an example of creating the object and setting it up:
AActor *OwnerActor = GetOwner(); // or another relevant actor in your context UGameplayAbilityPayloadComponent* PayloadComponent = NewObject<UGameplayAbilityPayloadComponent>(OwnerActor, FName(TEXT("GameplayAbilityPayloadComponent"))); if (PayloadComponent) { // You can set any additional properties and call functions on the PayloadComponent. // For example: FGameplayAbilityPayloadData PayloadData; // Populate your PayloadData here. PayloadComponent->SetGameplayAbilityPayloadData(PayloadData); } - User
UAbilitySystemBlueprintLibrary::SendGameplayEventToActor is not starting the ability on my local player
- Assistant
If the
UAbilitySystemBlueprintLibrary::SendGameplayEventToActor()function is not starting the ability on your local player, there might be several reasons for this. Let's go through some potential issues and their solutions: - User
PrimaryPC->DeprojectMousePositionToWorld(MouseWorldLocation, MouseWorldDirection) is failing on my ground actor for my local player. The local player is null even though we have the controller setup
- Assistant
If the
DeprojectMousePositionToWorld()function is failing and the local player is null even though the controller is set up, there could be several reasons for this issue. Let's walk through some potential solutions:- Check for NULL PlayerController:
Ensure that the
PrimaryPCobject is valid before calling theDeprojectMousePositionToWorld()function. You may want to add a check or log to verify that the PlayerController is not null:
- Check for NULL PlayerController:
Ensure that the
- User
- Assistant
Seeing that the issue is in the
Tick()function, I suggest checking if thePrimaryPCis being set correctly in your code. You commented out the following line:// PrimaryPC = UGameplayStatics::GetPlayerController(GetWorld(), 0);The
PrimaryPCis not being set anywhere in your code, which is likely the cause of the problem.GetWorld()would benullptrwhile initializing the component, so calling it in the constructor would not work.Instead, consider setting
PrimaryPCin the function: - User
This is using GAS. The primaryPC is setup here void UAbilityTask_WaitTargetData::InitializeTargetActor(AGameplayAbilityTargetActor* SpawnedActor) const { check(SpawnedActor); check(Ability);
SpawnedActor->PrimaryPC = Ability->GetCurrentActorInfo()->PlayerController.Get(); // If we spawned the target actor, always register the callbacks for when the data is ready. SpawnedActor->TargetDataReadyDelegate.AddUObject(const_cast<UAbilityTask_WaitTargetData*>(this), &UAbilityTask_WaitTargetData::OnTargetDataReadyCallback); SpawnedActor->CanceledDelegate.AddUObject(const_cast<UAbilityTask_WaitTargetData*>(this), &UAbilityTask_WaitTargetData::OnTargetDataCancelledCallback);} for the player controller that triggered the ability. The controller is getting set correctly but the local player is null. Since we are running on a listening server and the other client is not authoriative it makes sense for the local player to be null since it's the client. What's the best way to handle the other clients casting abilities using GAS?
- Assistant
When using the GAS (Gameplay Ability System) in a multiplayer environment with a listening server, you should use the correct components and delegates provided by GAS to handle the ability casting.
Instead of manually setting the
PrimaryPCin your task and relying on the tick function, you can override the task and implement custom input handling. This way, you can ensure your tasks only respond to the owner's inputs.