Suspiscious double call to GameMode member Function

Recommended Posts

I'm confused by this...

This is my function declaration and definition:

UFUNCTION(BlueprintPure, Category = "Spawn", meta = (BlueprintProtected))
		void RandomEmptySpawnLocation(FVector& Location);

void AWormGameMode::RandomEmptySpawnLocation(FVector& Location)
{
	TArray<int> RowWithSpaceID;
	TArray<int> ColumnWithSpaceID;
	for (auto rowID = 0; rowID < GridSlotsOccupiedMap.Num(); rowID++)
	{
		for (auto columnID = 0; columnID < GridSlotsOccupiedMap[0].BoolRow.Num(); columnID++)
		{
			if (!GridSlotsOccupiedMap[rowID][columnID])
			{
				RowWithSpaceID.Add(rowID);
				ColumnWithSpaceID.Add(columnID);
			}
		}		
	}
	int IDToUse = FMath::RandRange(0, RowWithSpaceID.Num() - 1);
	UE_LOG(LogTemp, Warning, TEXT("IDToUse = %i"), IDToUse)
	int MiddleColumnID = (GridWidth / GridBlockSize - 1) / 2;
	int MiddleRowID = (GridHeight / GridBlockSize - 1) / 2;

	Location.X = (ColumnWithSpaceID[IDToUse] - MiddleColumnID) * GridBlockSize;
	Location.Y = 50.f;
	Location.Z = (-RowWithSpaceID[IDToUse] + MiddleRowID) * GridBlockSize;
}

It simply check the bool map that contains the "Occupied/Empty" status for every grid slots, it stores the empty ones and then it picks one at random to be used as a spawn for pickup or player.

I am spawning 2 things, a pickup and a player, but as you can see from the console output, that function fired 4 times...

A row as ID ranging from 0 to 24 so ID 22 is the purple player, and ID 42 is the red pickup (24 + 18). But, there is nothing at ID 291 and 441...furthermore, I debugged step by step and only 2 spawn events happen, not 4... so why is my function called twice from every spawn event inside blueprint?!

I'll put below also the linkage of the function in blueprint, in case help to answer my doubt.

 

JEymwvO.png

image link

clMYMiN.png

Edited by MarcusAseth

Share this post


Link to post
Share on other sites

Are you sure that your actual event (Event Spawn Player) isn't being called more than you think? You might be explicitly triggering it twice that you know of, but deeper UE processes (such as duplication for PIE, CDOs) might result in indirect triggering of your event for various reasons. Put a breakpoint in the code and examine the call stacks to see where -- you'll have to pass through several layers of indirection (the BP invokes) which may be tricky to untangle if you've never done it before, but at the bottom of the stack you might find enough different roots to tell what is going on.

BlueprintPure can have an impact, anecdotally, on how the BP compiler evaluates nodes. Try temporarily making the function BlueprintCallable instead and see if that has any impact.

Share this post


Link to post
Share on other sites

Thanks jpetrie, I replaced the BlueprintPure with a BlueprintCallable, and indeed it solved it, it is run only once :)

But before that, with the BlueprintPure version I've also put a breakpoint and run the Debug tab as you suggested, image below, as you can see Event Spawn Player is called once, but the SpawnActor (engine default node) is being called twice consecutively (and thus summoning my function twice), is this normal behaviour? It has to do with the deeper UE processes you mentioned?

If so, it is safe to assume that BlueprintPure is less performant than just plain Blueprint Callable, based on the fact it runs my function(which internally calls FMath::RandRange and a for loop with roughly 600 iterations) twice at every spawn? 

Another question that arise is, is the second SpawnActor call actually used for something or is thrown away?! Because if it is used, I now have a bug since I'm providing 2 different (random) resoult to the same spawned actor, and I don't know how the engine is using those resoults for... o_O

 

nBEnomB.png

Edited by MarcusAseth

Share this post


Link to post
Share on other sites
38 minutes ago, MarcusAseth said:

But before that, with the BlueprintPure version I've also put a breakpoint and run the Debug tab as you suggested, image below, as you can see Event Spawn Player is called once, but the SpawnActor (engine default node) is being called twice consecutively (and thus summoning my function twice), is this normal behaviour? It has to do with the deeper UE processes you mentioned?

 

I meant actually break in Visual Studio. That Blueprint Debug tab and associated stack trace is, in my experience, completely useless.

39 minutes ago, MarcusAseth said:

If so, it is safe to assume that BlueprintPure is less performant than just plain Blueprint Callable, based on the fact it runs my function(which internally calls FMath::RandRange and a for loop with roughly 600 iterations) twice at every spawn? 

 

It's not really safe to assume anything about the performance in general. A BP pure function is one where the invocation of the function has no side-effects on the invoking object. This means the compiler can optimize around the node, and organize it, with that assumption in mind. This can result in the compiler calling the pure function more often than it would "need," (for example, once per input pin its attached to, once per time it needs the value, et cetera) because it is safe to do so, and it means the compiler need not reserve any storage for the results of the function. But the BP compiler can't tell how complex the pure node is if the body is native code, so there's no way for it to tell if the pure function is a cheap getter or a complex calculation. If your function is complex and the compiler decides to call it one for every input pin attached to it, you might see performance issues.

The "purity" of pure functions isn't really enforced either. If you, for example, increment a global variable in a pure function, the BP compiler isn't really going to know about that and you might get some interesting results.

52 minutes ago, MarcusAseth said:

Another question that arise is, is the second SpawnActor call actually used for something or is thrown away?! Because if it is used, I now have a bug since I'm providing 2 different (random) resoult to the same spawned actor, and I don't know how the engine is using those resoults for... o_O

 

I don't quite understand this problem description, unfortunately.

Share this post


Link to post
Share on other sites

I've just realized I'm seeying this "side-effect" a lot but I always fail to understand it, what does "side-effect" represent in this context? :/

Also I think I've managed to debug it from VS, though I don't know what to make of the resoult. Below the image, the two different screenshot are the first and the second time we enter that function, and the stack is the same in both cases (Are we jumping back up the stack?!), also to keep it simple I only spawned 1 thing, the player. 

Quote

I don't quite understand this problem description, unfortunately.

I mean, my function is returning a random Location. If I link it to 1 pin of a SpawnActor, I expect it to return 1 and only 1 resoult. But if behind the scenes it gets called twice, 1 random location is used to set the actor location in the scene, but I have no idea what the second is used for. For what I know, maybe the editor need to keep a copy of the value so that's why it calls it again, but instead of the current value it is getting a new random location, and that's why I'm asking if this is the case that this could create problems.

 

Also a thing interesting to notice:  Even though if I make it BlueprintCallable (thus getting the execution pin) it is called only once as one would expect, if I also make the function "const" (which remove the execution pin, making it identical to BlueprintPure in appearance inside the BPEditor) then it behave like the BlueprintPure, meaning it is called twice per spawn again :|

What should I make out of this? x_x

EDIT: side note: I am trying to give you a Thanks, but when I refresh the page the Thanks gets removed... is this a bug?

QpUZMiF.png

Edited by MarcusAseth

Share this post


Link to post
Share on other sites

A "side-effect" means that a function changes something as well as just giving you a value back. In mathematics, a function usually has no side-effects. sqrt(x) returns the square root of x to you but nothing changes, no matter how many times I call that function. But if I call decreaseHitpoints(character), then something in that character object is likely to get changed, so it matters how often I call it.

Pure functions with no side-effects are great because the results can be cached forever, they are easily tested, they don't care which order they're called in, etc.

Arguably, functions that include random number generation cannot be pure functions, because they do have hidden side-effects - the random number generator changes state so that it can generate a new value next time. Whether this is relevant or not to UE4 or your situation is probably debatable, but I'd flag this function as Callable rather than Pure, and be done with it.

Just putting this out there: sometimes an event appears to get called multiple times in UE4 because it's running on both the client and the server. Do you have multiplayer enabled?

As for your call stack, obviously that's worthless, unfortunately. I'm used to running from a full source build so I can see where things are called from.

Share this post


Link to post
Share on other sites

@Kylotan Thank you for the great explanation, much more clear now!

Regarding the multiplayer, I've started a new Blank Project with no starting content, so unless multiplayer is on by default, it should be off (I won't even know where to touch to enable it).

Also making it BlueprintCallable is the way I went, makes me nervous otherwise.

Well, that's being said, below is my first game ever, and is crap :D (I mean is boring)

 Moving on to something else :)

 

Edited by MarcusAseth

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Forum Statistics

    • Total Topics
      628667
    • Total Posts
      2984139
  • Similar Content

    • By nihitori
      This is the official Sales topic for the acclaimed Colossal Game Music Collection (100+ five-star ratings on the Unity Asset Store) and its Lite version, the Essential Game Music Collection.

      Updates will be made here every time a sale is taking place on either the Unity Asset Store or the Unreal Engine Marketplace.

      Current Sales:

      Christmas Madness 2016 Sale on the Unity Asset Store -

      - Colossal Game Music Collection at 75% OFF - https://www.assetstore.unity3d.com/en/#!/content/88190


      Please feel free to post here any questions you might have about either the sales or the collection itself.
    • By Anderfell
      **[ROYALTY]**
       
      Hello my name is Brandon and I am currently one of the co owners of the team Digital Forged Studios.
       
      We are currently seeking two new members for our team, before applying you must be aware that we are seeking people that are 100% committed to this project, you must be reachable within the day, replying to questions or responding to our messages and in general be actively online, otherwise I ask nicely that you do not apply.
       
      The persons we are seeking are an experienced Programmer with knowledge  in c++, c#, and or unreal script, the c++ and familiarity with unreal is the main thing were seeking, other teams we are currently looking for are 3D artists to work on Humanoid models Props and more, were are also seeking other team members such as Generalists that understands the Unreal Engine, Animators for Human, Non Human and Objects were keeping the team small and having whats needed so feel free to apply.
      ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
      [SEEKING CURRENT POSITIONS]
       
      [Animators] x 2 [ You will be doing Human, Non Human, and Objects like Machines and Doors, Environment assets. ]
      [3D Artist] x 2 [ You will be focusing on Humans, Objects, and Environment modeling would also like skills in texturing. ]
      [Generalist] x 1 [ We would like someone that has good knowledge of Unreal Engine that can set up anything we need in Engine. ]
      [Writer] x 1 [ We would need someone that can work with me on game documents, organisation of documents story arcs, character development, dialogue creation, text editing and other text related jobs. ]
      [PROGRAMMER] "As above"
       
      The project is Royalties and when any fund raising is made you will also receive some funding based off that, this is divided depending on amount of work done as an example per asset made toward the game, there are no contracts at this stage and everything known is in documents at the moment.
       
      The game is a Action RPG with online elements this will be an ongoing project, we are running ssh servers, and Prefroce. We have a small staff of experienced people.
       
      ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
      We do have some artwork to show of the world a little and what it's about, If you are interested in joining the project please contact us at:
       
      Anderfell info:
      Anderfell#5123 on Discord
      nevarra@hotmail.com email
       
      Shadefix info:
      Shadefix#0570 on Discord
      androes.matthijssens@gmail.com email
      We are active on Discord and maybe take a day or two to reply to emails on our website as we receive a few a daily we need to sort through thanks. 
      https://digitalforgedstudios.com/
      ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
      Comic Panel
      http://imgur.com/a/905pd
       
      Artwork
      http://imgur.com/a/0JchV
      Models
      http://imgur.com/a/jdhWu
       
      Game Document
      https://docs.google.com/document/d/1bNlP-qwR15BLGG66hDUcewqlWIPP4flnHxRwxfhNmTE/edit?usp=sharing
       
      Regards Brandon
      Digital Forged Game Development Team.
       
      Some Progress
       





       
       





    • By i3DTutorials
       

       
      Game School Online™ Announces Winter Enrollment Open Through December
      Los Angeles, CA - December 2017
       
      Free Winter Term Enrollment!
      Free Winter Enrollment:
      Game School Online™, the first and only free online game development school of its kind, has opened enrollment for the winter term, which begins in January of 2018. GSO™ currently offers curricula in environment art and lighting for games, focusing specifically on Unreal Engine 4. GSO™ will be adding two new courses for the winter term, “Advanced Lighting Concepts with Unreal Engine 4” and “Advanced Hard Surface Modeling.”

       
      Free Workshop!

       
      December Free Workshop:
      In addition to winter enrollment, GSO™ will have a free online workshop, “Animating For Games and Movies”, with Veara Suon, Senior Animator at Double Negative. Veara has worked in the AAA games industry, working on franchises like Destiny and Bioshock. Veara also works in the film industry, having worked for famed studios like Weta, ILM, and Sony, contributing to films like Pacific Rim 2, Spiderman, and Avengers. In this month’s free GSO™ workshop, Veara will be discussing topics such as:
      Sharing techniques on how he animates for games and film
      Advice on how students can get a job in games or film
      Advice on how working professionals can switch from games to film, and vice versa
      Job relocation
      The workshop will last for an hour, with allocated time for Q & A from the audience. The workshop will take place on December 14 at 8pm PST. As usual, our monthly workshops are absolutely free and anyone is welcomed to join us. To RSVP, please visit our Facebook page here: https://www.facebook.com/events/139461393377301/?active_tab=about

       
      Scholars Available For Mentoring!
      Scholar Lineup:
      Scholars are our mentors, working industry professionals currently working on your favorite games and franchises- here to help you learn to be a professional game dev, with one on one live private sessions. Our current lineup of scholars includes:
       
      Brian Yam - Director of Visual Development @ Section Studios
      https://bdyammer.artstation.com/
      https://www.linkedin.com/in/yambrian/
       
      Olaf Piesche - Senior Engineer @ Epic Games
      https://www.linkedin.com/in/olaf-piesche-0938292/
       
      Kevin DeBolt - World Artist @ 343 Industries
      http://kevindebolt.com/index.html
      https://www.linkedin.com/in/kevin-debolt-52058844/
       
      Rosie Katz - Senior Game Designer @ EA, Visceral, Sledgehammer Games
      http://www.rosiewrede.com/index.php?nav_bar=level_design
      https://www.linkedin.com/in/rosiewrede/
       
      Leo Gonzalez - Senior Artist @ Certain Affinity
      https://leog.artstation.com/
      https://www.linkedin.com/in/leo-g/
       
      Brandon Pham - Lead Environment Artist
      https://brandonpham.artstation.com/
      https://www.linkedin.com/in/brandon-pham-a490497/

       
      We believe that education should be free for everyone! Come join us at Game School Online™ and see what the future of game development education looks like today! For more information about Game School Online™, available courses, scholars, and events, please visit http://gameschoolonline.com/


       
      Facebook: https://www.facebook.com/gameschoolonline/
      Twitter: @GSOscholar
      Discord: https://discordapp.com/invite/BzU5Fq2
      Patreon: https://www.patreon.com/gameschoolonline


       
      About Game School Online™ (GSO™)
      Game School Online™ is the first ever, completely free game development training program. GSO™ was founded by veteran developers working in the AAA games and entertainment industries. Featuring courses authored by working industry professionals, students are able to learn production techniques and workflows used to ship some of the biggest IPs and AAA franchises. Industry pros known as “scholars”, work with students providing private live sessions to help you become “industry” ready. All courses are available for free, no trials or demos- it’s completely free for anyone that wants to learn how to become a skilled game developer. For more information, please visit our website: http://gameschoolonline.com/
      Game School Online™ and GSO™ are registered trademarks Game School Online, LLC. All other brand names, product names or trademarks belong to their respective holders.
       
      Contact
      Game School Online, LLC.
      info@gameschoolonline.com

      View full story
    • By i3DTutorials
       

       
      Game School Online™ Announces Winter Enrollment Open Through December
      Los Angeles, CA - December 2017
       
      Free Winter Term Enrollment!
      Free Winter Enrollment:
      Game School Online™, the first and only free online game development school of its kind, has opened enrollment for the winter term, which begins in January of 2018. GSO™ currently offers curricula in environment art and lighting for games, focusing specifically on Unreal Engine 4. GSO™ will be adding two new courses for the winter term, “Advanced Lighting Concepts with Unreal Engine 4” and “Advanced Hard Surface Modeling.”

       
      Free Workshop!

       
      December Free Workshop:
      In addition to winter enrollment, GSO™ will have a free online workshop, “Animating For Games and Movies”, with Veara Suon, Senior Animator at Double Negative. Veara has worked in the AAA games industry, working on franchises like Destiny and Bioshock. Veara also works in the film industry, having worked for famed studios like Weta, ILM, and Sony, contributing to films like Pacific Rim 2, Spiderman, and Avengers. In this month’s free GSO™ workshop, Veara will be discussing topics such as:
      Sharing techniques on how he animates for games and film
      Advice on how students can get a job in games or film
      Advice on how working professionals can switch from games to film, and vice versa
      Job relocation
      The workshop will last for an hour, with allocated time for Q & A from the audience. The workshop will take place on December 14 at 8pm PST. As usual, our monthly workshops are absolutely free and anyone is welcomed to join us. To RSVP, please visit our Facebook page here: https://www.facebook.com/events/139461393377301/?active_tab=about

       
      Scholars Available For Mentoring!
      Scholar Lineup:
      Scholars are our mentors, working industry professionals currently working on your favorite games and franchises- here to help you learn to be a professional game dev, with one on one live private sessions. Our current lineup of scholars includes:
       
      Brian Yam - Director of Visual Development @ Section Studios
      https://bdyammer.artstation.com/
      https://www.linkedin.com/in/yambrian/
       
      Olaf Piesche - Senior Engineer @ Epic Games
      https://www.linkedin.com/in/olaf-piesche-0938292/
       
      Kevin DeBolt - World Artist @ 343 Industries
      http://kevindebolt.com/index.html
      https://www.linkedin.com/in/kevin-debolt-52058844/
       
      Rosie Katz - Senior Game Designer @ EA, Visceral, Sledgehammer Games
      http://www.rosiewrede.com/index.php?nav_bar=level_design
      https://www.linkedin.com/in/rosiewrede/
       
      Leo Gonzalez - Senior Artist @ Certain Affinity
      https://leog.artstation.com/
      https://www.linkedin.com/in/leo-g/
       
      Brandon Pham - Lead Environment Artist
      https://brandonpham.artstation.com/
      https://www.linkedin.com/in/brandon-pham-a490497/

       
      We believe that education should be free for everyone! Come join us at Game School Online™ and see what the future of game development education looks like today! For more information about Game School Online™, available courses, scholars, and events, please visit http://gameschoolonline.com/


       
      Facebook: https://www.facebook.com/gameschoolonline/
      Twitter: @GSOscholar
      Discord: https://discordapp.com/invite/BzU5Fq2
      Patreon: https://www.patreon.com/gameschoolonline


       
      About Game School Online™ (GSO™)
      Game School Online™ is the first ever, completely free game development training program. GSO™ was founded by veteran developers working in the AAA games and entertainment industries. Featuring courses authored by working industry professionals, students are able to learn production techniques and workflows used to ship some of the biggest IPs and AAA franchises. Industry pros known as “scholars”, work with students providing private live sessions to help you become “industry” ready. All courses are available for free, no trials or demos- it’s completely free for anyone that wants to learn how to become a skilled game developer. For more information, please visit our website: http://gameschoolonline.com/
      Game School Online™ and GSO™ are registered trademarks Game School Online, LLC. All other brand names, product names or trademarks belong to their respective holders.
       
      Contact
      Game School Online, LLC.
      info@gameschoolonline.com
    • By Ben3d
      My new contribution. I hope you will like it. Details here.
  • Popular Now