Summer Work (Day 9)

In Editor Live Updating pt.1

    For the past few days I worked on getting the resolution of the planets to be editable inside the blueprint editor and to make it update in real time. After many false leads, I have finally figured it out. 

    The solution comes as a combination of two things; UPROPERTY specifiers and an editor function. The UPROPERTY specifiers that I used were EditAnywhere and BlueprintReadWrite. EditAnywhere allows the property to show up in the details panel, and BlueprintReadWrite allows the value to be written to effect the C++. Though, I think I will end up using EditInstanceOnly over EditAnywhere when I move to using the planets in the scene. One of the red herrings I ran across while looking into the specifiers was the metadata specifier BlueprintCompilerGeneratedDefaults. This was because, at the time, I thought that I had to set the initial value to the blueprint value and reinitialize from there. As it turns out though, it doesn't really matter what the value is initialized to because it can always be changed during runtime with the editor function.
    This function is PostEditChangeProperty and is inherited by all children of AActor. This function, when you understand how to use it, is extremely powerful and much more customizable than the Unity function OnValidate() that was used in the tutorial. I found this function many time in my research for the best way to do it, but it was this book that really explained how it worked and how to use it.  In my script, it looks like this: 
void APlanet::PostEditChangeProperty(FPropertyChangedEvent & PropertyChangedEvent)
{
	if (PropertyChangedEvent.Property != nullptr)
	{
		const FName PropertyName(PropertyChangedEvent.Property->GetName());
		if (PropertyName == GET_MEMBER_NAME_CHECKED(APlanet, resolution))
		{
			GeneratePlanet();
		}
	}
	Super::PostEditChangeProperty(PropertyChangedEvent);
}

    Right now it is only used for updating the planet generation when the planet's resolution is updated. In the future I plan to also use it for color and shape settings. Right now though, I am trying to implement these settings as data assets.

Comments

Popular posts from this blog

Polishing the Foundation

Progress Update #13

A New Chapter