#Null check thingy

1 messages · Page 1 of 1 (latest)

gaunt garnet
#

I refactored my code few times and now its in a raw state

#

I want to make that when im trying to use systems i would not want to create null checks in systems that refers to another systems.

Example :
StashGiveTrigger should only collides with objects that has specific layer(done in unity editor layer matrix)
StashGiveTrigger should only give item if stash has this item and do not throw error (null check)

I should not write code that will check if giving item is a null

vale reef
#

give me line

gaunt garnet
#

I tried to create something like this:


public bool TryGet(out Pickupable item)
{
  if (stack.TryPop(out item)) return true;

  return false
}
#

but then i anyway should write:

if (!stash.TryGet(out var item)) return
_playerStash.Add(item);
vale reef
#

whats the point of try pop if you still have the same amout of code using Count?

#

well ok you save a line

gaunt garnet
#

When I want to :

public StashBase _stash;

public void OnTriggerStay(Collider other)
{
  var playerStash = other.GetComponent<StashBase>();
  var item = playerStash.GetItem();
  _stash.Add(item);
}

#

I don't want to add null checks here I would rather add them inside systems, that will be operated.

#

But now people saying that null check are not good and I cannot understand why.

vale reef
#

its not null check problem

#

its bound check

gaunt garnet
#

Oh, by null check I mean all checks that executes exception

vale reef
#

you essentially are accessing a finite collection and ensuring its in bounds

#

theres no way around checking if the collection is empty

#

you cant avoid checking its count when iterating either, and its not a null check

#

now if you have a non 0 count stack and you retreive an item that is null - thats a valid null exception

gaunt garnet
#

Oh also

vale reef
#

there shouldnt be a scenario where you try to push a null

gaunt garnet
#

let me show you game loop clip

#

to visually show you

vale reef
#

oh its that one

#

the one i showed you how to use a simple list to solve it

gaunt garnet
#

When object spawner has 0 items in stack and I try to get item from this stack i receive an error InvalidOperationException. When before I knew that would happen and in trigger script added check code to ignore this scenario

vale reef
#

yes its valid

#

bounds check on collection you know will be empty is 100% valid

gaunt garnet
#

its valid but i don't quite like it and think that i can do it inside system rather checking it in trigger class that should only do the operation part

vale reef
#

its not an error or malpractice

gaunt garnet
#

Also collision, trigger part is hard for me because I don't know how to handle it better

#

I come up with Excluding Collision Layers in Editor, Creating Trigger gameobjects, changing gameobjects layer, adding needing script and thats is ok for me

vale reef
#

yeah that is good when you are sure you are adhering to it

#

imagine you have a team of 10 people where everyone makes these objects

#

and 2 out 10 people forget to set the layers

#

you need validation of data

#

you need to raise exceptions there or on runtime

gaunt garnet
#

yes

#

Your explanation about exceptions are great

#

and i have new things to try out

#

before i was too lazy about it

vale reef
#

you remind me of me somewhat i also was into all the cool practices

#

eventually tho it leads to near impossible to navigate and reason about code

gaunt garnet
#

I think everyone goes through this period

#

Now I'm trying to create project that will be easy to use and extendable

#

Want to add personal thing into this conversation

#

I'm self-taught programmer that tried to get a job too many for too long. For about 2 years i've been trying to get a job after 2-3 portfolio projects. I was learning alot about SOLID, OOP patterns, best practises. But in the end i still cannot find a job and i ended up with no games in this period. Now, with this project Im trying to master everything that i learnt.

vale reef
#

make something hard

gaunt garnet
#

Make a game is much easier for me than get a job XD

vale reef
#

some spherical pathfinding system, some complex shaders, stuff like that

#

you dont need to grind IoC to get a job, basic oop principles will suffice, you need to show you are not a "script kiddie"

gaunt garnet
#

Oh ye, shaders part is hard for me, just don't know where to begin. Unity has Shader graph but its not usable without shader knowledge

vale reef
#

its an example

#

you can do some traffic system with lanes, procedural generation, marching cubes/wpf/raymarching whatever

gaunt garnet
#

I was trying to show that I can do something, that i want to do something and I can improve

vale reef
#

any "hard" tech that average hypercasual developer cant comprehend

#

but yeah if you fail so much interviews it may boil down to lack of basics

#

questions like - what is boxing and when it happens

gaunt garnet
#

That's true. I lack in basics.

#

At that time i could not understand why I need to know about garbage collection and heap when Im gonna make hypercasual game that will die next day

#

Also. I have a question about mobile and pc developing

vale reef
#

its best not to ask me

#

i dont do mobile and avoided it at all costs

gaunt garnet
#

I want to create pc games, mobile development for me was entry point. Is it better go to UE5 now or I can still make great games in Unity?

vale reef
#

for real ? 😄

gaunt garnet
#

?

vale reef
#

unity is a choice for people who build up games from ground up, or those who abuse asset store

#

unity is genre/type of game agnostic

#

it fits any genre and is loved for the development speed, asset pipeline, safe bet language

gaunt garnet
#

I chose Unity coz I don't want to use blueprints in UE

vale reef
#

well in ue you can use c++ since its not even c++ at this point

#

it has reflection, garbage collection, everything is simplified

#

you have macros for all things

gaunt garnet
#

And also i really love ECS now and waiting when unity will done this. Learnt basics when was using LoeECSLite

vale reef
#

its basically c# with a different syntax

gaunt garnet
#

It felt like that they created script wrapper

gaunt garnet
vale reef
#

blueprint as in actor?

#

actor is just serialized data from c++ class

#

there are 2 kinds of bp in ue, one is actual noodles

#

another is "prefab"

#

your cpp extended actors are "blueprints" in a "prefab" sense

#

you dont need to convert c++ to noodles

#

maybe expose functions to bp, but not "convert"

gaunt garnet
#

what do you mean by noodles? nodes?

vale reef
#

spaghetti

gaunt garnet
#

oh you literally mean noodles XD

vale reef
gaunt garnet
#

yea i was thinking about that and thought nodes

gaunt garnet
#

thats why i chose Unity

vale reef
#

its not a valid reason tbh

#

unity has visual scripting as well

#

with EXACTLY the same concepts

gaunt garnet
#

I just don't like visual scripting

vale reef
#

so the results will be the same

#

then dont use it in ue

#

see there is an actual reason you chose unity over ue, you just dont state it

#

blueprints are optional, so that is not a valid reason

gaunt garnet
#

i do not know that they are optional

#

I thought you have 2 paths with ue

use blueprints

c++ / convert to blueprint / use blueprint

vale reef
#

you probably got confused by naming

gaunt garnet
#

probably i misheard somewhere

#

I thought : Wth? I want to code and create systems with code. I don't want to look at this noodles

vale reef
#

in ue in cpp you do exactly the same thing as in unity

#

extend Actor / ActorComponent

#

write tick code

#

expose properties

#

void APickup::Tick(float DeltaTime)
{
  Super::Tick(DeltaTime);
  FVector NewLocation = GetActorLocation();
  if (NewLocation.Z > 50.0f) {
    bImGoingUp = false;
  } else if (NewLocation.Z < -50.0f) {
    bImGoingUp = true;
  }
  float factor = (bImGoingUp ? 20.f : -20.f);
  NewLocation.Z += factor * DeltaTime;
  SetActorLocation(NewLocation);
}
gaunt garnet
#

Yea thats like MonoBehaviour

vale reef
#

yeah

gaunt garnet
#

But often i don't want to use MonoBehaviour

#

can i do this with ue?

vale reef
#

of course if its not an actor

gaunt garnet
#

so how i should inject it?

vale reef
#

not sure, probably through one of the game manager/systems extension points

gaunt garnet
#

Also, what your thoughts on ue5?

vale reef
#

same as unity

#

ue5 is pretty

#

graphics strong

#

thats all

#

same engine, same usage context

gaunt garnet
#

After ue4 editor ui i was hoping that they will do something

#

o boy how i like it now

#

this ctrl space content opener shortcut is a game changer

vale reef
#

this is fluff

#

its same ue in its core

gaunt garnet
#

Yea i understand

#

but just this redesign made experience much better

#

But still its hard for me to operate with zero experience. I tried to look how they made third person controller movement and failed. Tried to check how animation flow works (like in unity when you can open animator in runtime and check node logic)

vale reef
#

unreal is a beast in tooling for your "classic" AA / AAA titles

#

beast in graphics

#

but if you are not aiming at it, its all useless to you and only drags down

gaunt garnet
#

yea true

vale reef
#

Rimworld / Cities Skylines / Dyson Sphere Project

#

all use unity

#

those are very complex games, and they chose unity for numerous reasons

#

but main one is - unity is agnostic to its use

gaunt garnet
#

I want to create roguelikes, multiplayer games, coop games, Third person games, arena games (like wow arena pvp).

#

souls-rogue like games XD

#

And when Unity announced that they will add Entities 1.0 in the next year i was so happy

gaunt garnet
#

Anyway, thanks for the conversation and help. Really needed this conversation. I am not a native English speaker, so sorry if I wrote grammatical nonsense XD