Help using a GUID in C++ [ue4.27]

I should probably preface this by saying I’m not fluent in Cpp, but I am looking to improve.

I currently have an actor base class with the following property:

UPROPERTY(BlueprintReadWrite, VisibleAnywhere, SaveGame)
	FGuid actorID;

and I created the following function to set the GUID:

void ACE_EditorActorBase::SetNewGUID()
{
	if (!actorID.IsValid())
	{
		actorID = actorID.NewGuid();
	}
}

I was hoping to be able to simply call this function in the constructor so that the GUID would always be set on any actor inheriting this class like so:

ACE_EditorActorBase::ACE_EditorActorBase()
{
	PrimaryActorTick.bCanEverTick = true;
	SetNewGUID();
}

When I switch to the editor and check the validity of the GUID however, nothing appears to have worked (the variable does show up etc, but is not set). Would someone possibly be able to give me a nudge in the right direction? Hopefully I’m not too far off but its also possible that I am… xD

My end goal is to serialize the data to a save file and then restore saved values etc., and the actors are all created during gameplay.

Thanks in advance! <3

So just to follow up on the off chance someone happens to find themselves in this situation. I made a slight mistake in my function when trying to set the GUID. The following function works now:

void ACE_EditorActorBase::SetNewGUID()
{
	if (!actorID.IsValid())
	{
		actorID = FGuid::NewGuid();
	}
}

Seems like the ‘::’ is needed instead of a simple ‘.’ to call a static function.

This is neat. I was thinking of doing something similar. Though I was also wanting a GUID for instanced actors (placed by hand or foilage painter) to have a GUID that’d not change, but differ from instance to instance.

Still researching, but I’d thought to create an inherited actor base class too to handle this. It’s actually a shame. There is an ActorGuid built into the actual Actor class, but it is only available in development builds for whatever reason.

Thinking on this some more. I just created this ActorBase.cpp class, but I realize that game classes that inherit from say Character won’t be using it. Kind of defeats the need for this.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.