AndrewScheidecker / BrickGame

A demo of Minecraft-style voxel rendering in UE4
401 stars 143 forks source link

How to use BrickGridComponent's Update method #7

Closed StenBone closed 9 years ago

StenBone commented 9 years ago

I do not understand how to call the Update method in the BrickGridComponent class. I understand all the input variables except the last one defined as "FBrickGrid_InitRegion InitRegion".

Would someone please give an example of how to properly call this Update method from code using a BrickGridComponent variable.

AndrewScheidecker commented 9 years ago

When you call Update, it iterates over regions within some distance (https://github.com/AndrewScheidecker/BrickGame/blob/master/Plugins/BrickGrid/Source/BrickGrid/Private/BrickGridComponent.cpp#L360), and calls the provided InitRegion delegate for any regions that haven't been initialized yet (https://github.com/AndrewScheidecker/BrickGame/blob/master/Plugins/BrickGrid/Source/BrickGrid/Private/BrickGridComponent.cpp#L387).

The FBrickGrid_InitRegion delegate type is declared here: https://github.com/AndrewScheidecker/BrickGame/blob/master/Plugins/BrickGrid/Source/BrickGrid/Classes/BrickGridComponent.h#L219

You can find general information about UE4's delegate system here: https://docs.unrealengine.com/latest/INT/Programming/UnrealArchitecture/Delegates/index.html#declaringdelegates

The BrickGrid blueprint just calls Update with a delegate that passes the region coordinates through to UBrickTerrainGenerationLibrary::InitRegion along with a pointer to the brick grid and the terrain generation parameters.

StenBone commented 9 years ago

Thank you for the information @AndrewScheidecker. It really helped me wrap my head around how the delegates were setup in the project.

I did some experimenting and I finally ended up with this in my InitGridRenderingAndCollision() method.

    FBrickGrid_InitRegion myDelgate;
    myDelgate.BindUFunction(this, "InitRegion");
    BrickGridComp->Update(UGameplayStatics::GetPlayerCameraManager(this, 0)->TransformComponent->GetComponentLocation(), MaxDrawDistance, MaxCollisionDistance, 100, myDelgate);    

It does compile properly, but I am still a bit unsure on some of the details, so it will take future testing to determine whether or not this solution works.