Hi,
I’m trying to figure out why an object created with ConstructObject is set to NULL when leaving the function where it was created. I assume that this is somehow related to the GC, but I do not understand why and what I can do against it.
My CreateAndAddTeam-function will call CreateTeam, where I construct a new team.
In CreateTeam, the team is properly constructed, meaning, not NULL. But after returning to the calling function (in this case CreateAndAddTeam), the returned pointer is set to NULL.
Below is the code:
/**
* TRUE, if the team was added to the team manager.
* @param teamType The team to create and add
* @param team the created and added team or NULL
* @param bUnique should only be one team of this type (default = true)
* @return true: team added by team manager, false: else
*/
bool UTeamManager::CreateAndAddTeam(TSubclassOf<class UBaseTeam> teamType, UBaseTeam* team, bool bUnique)
{
bool ok = true;
if (bUnique || bForceUniqueTeamTypesOnly)
ok = !HasTeamType(teamType);
// Creates and adds the team
ok = ok && CreateTeam(teamType, team);
ok = ok && (team != NULL);
ok = ok && AddTeam(team);
if (!ok)
team = NULL;
return ok;
}
/**
* Creates the team from a team type.
* @param teamType The type of the team
* @param team The team created (or null)
* @return true: successful, false: else
*/
bool UTeamManager::CreateTeam(TSubclassOf<class UBaseTeam> teamType, UBaseTeam* team)
{
bool okay = false;
team = NULL;
team = ConstructObject<UBaseTeam>(
teamType,
this,
NAME_None,
RF_NoFlags,
NULL,
false,
NULL);
okay = (team != NULL);
return okay;
}
When looking at the runtime variables, the following can be observed:
- After calling ConstructObject in the function CreateTeam-function (just before returning to the calling function)
- Directly after returning from CreateTeam in the CreateAndAddTeam-function
Thanks for your help.
~Julian